Dating with girls(1)

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2127    Accepted Submission(s): 730

Problem Description
Everyone in the HDU knows that the number of boys is larger than the number of girls. But now, every boy wants to date with pretty girls. The girls like to date with the boys with higher IQ. In order to test the boys ' IQ, The girls make a problem, and the boys who can solve the problem 
correctly and cost less time can date with them.
The problem is that : give you n positive integers and an integer k. You need to calculate how many different solutions the equation x + y = k has . x and y must be among the given n integers. Two solutions are different if x0 != x1 or y0 != y1.
Now smart Acmers, solving the problem as soon as possible. So you can dating with pretty girls. How wonderful!
 
Input
The first line contain an integer T. Then T cases followed. Each case begins with two integers n(2 <= n <= 100000) , k(0 <= k < 2^31). And then the next line contain n integers.
 
Output
For each cases,output the numbers of solutions to the equation.
 
Sample Input
2
5 4
1 2 3 4 5
8 8
1 4 5 7 8 9 2 6
 
Sample Output
3
5
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  2575 2579 2573 2576 2574 
 
 //1968MS    2000K    551 B    G++
//1421MS 1932K 551 B C++
/* 题意:
给你n个数,和一个数k,问n个数中有多少d对不同的x、y使
x+y=k 成立
x可以等于y hash:
直接使用C++的map容器做映射。
注意一点就是要排序,避免出现相同的x、y */
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(void)
{
int t,n,k,a[];
scanf("%d",&t);
while(t--)
{
map<int,int>M;
M.clear();
scanf("%d%d",&n,&k);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
if(M[a[i]]==) M[a[i]]=;
}
sort(a,a+n);
int ans=;
a[n]=-;
for(int i=;i<n;i++)
if(M[k-a[i]]== && a[i]!=a[i+]) ans++;
printf("%d\n",ans);
}
return ;
}

最新文章

  1. animate对颜色设置不起作用
  2. 在Mac mini上安装 ESXi 5.5
  3. Oracle中PL/SQL简介、基本语法以及数据类型
  4. C# 读写excel 用于导入数据库 批量导入导出excel
  5. python测试api接口
  6. Struts2的国际化
  7. linux环境下安装php扩展
  8. 使用GitHub管理源代码
  9. 利用Python进行数据分析——数据规整化:清理、转换、合并、重塑(七)(1)
  10. Android Studio非gradleproject编译后的apk文件在哪?
  11. SecureCRT + Tmux 分屏 高效开发
  12. 深度理解DOM拷贝clone()
  13. Codeforces Round #479 (Div. 3) C. Less or Equal
  14. Redies安装,修配置,设置密码,
  15. Connection open error . Connection Timeout Expired. The timeout period elapsed during the post-login phase.
  16. decode函数解决oracle报错&quot;除数为0&quot;的问题
  17. Fiddler安装证书
  18. 3、JPA-API
  19. 【工具相关】Web-ionic-ionicLab的使用
  20. Android 好用和常用的控件

热门文章

  1. SQL递归查询实现组织机构树
  2. ABAP调用WebService时日期类型问题
  3. Jenkins搭建CI/CD
  4. 复用传统C/S架构系统,升级成‘伪’B/S架构设计
  5. 如何设置 html 中 select 标签不可编辑、只读
  6. php jsonp实例 mip无限滚动组件接口注意事项
  7. Python全栈day 05
  8. Cache、Buffer的区别
  9. 笔记-scrapy-辅助功能
  10. Hadoop三大发行版本