HDU2578——Dating with girls
来源:互联网 发布:局域网控制电脑软件 编辑:程序博客网 时间:2024/06/06 07:34
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!
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
25 41 2 3 4 58 81 4 5 7 8 9 2 6
Sample Output
35
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int a[100005];int main(){ int t; int n,m; int i,j; int k; cin>>t; while(t--) { cin>>n>>k; for(i=1; i<=n; i++) scanf("%d",&a[i]); a[0]=-99999; sort(a,a+n+1); int count=0; int big,small; int mid; for(i=1; i<=n; i++) { if(a[i-1]!=a[i]) { big=n; small=1; while(small<=big) { mid=(big+small)/2; if(a[mid]+a[i]==k) { count++; break; } if(a[mid]+a[i]>k) big=mid-1; else small=mid+1; } } } cout<<count<<endl; } return 0;}
- HDU2578——Dating with girls
- HDU2578.Dating with girls(1)——二分
- HDU2578:Dating with girls(1)
- HDU2578 Dating with girls(1)(二分)
- HDU2578 Dating with girls(1)(二分)
- HDU2578--Dating with girls(1) (map||排序+二分)
- ACM-简单题之Dating with girls1——hdu2578
- hdu 2578——Dating with girls(1)
- ACM-BFS之Dating with girls(2)——hdu2579
- Dating with girls(1)
- Dating with girls(1)
- Dating with girls(2)
- Dating With Girls
- Dating with girls(1)
- Dating with girls(2) HDU
- HDU 2579 Dating with girls(2) BFS
- HDU 2579 Dating with girls(2)
- hdu 2579 Dating with girls(2)
- Eclipse远程调试Tomcat
- POJ 1637 Sightseeing tour
- UVa - 152 - Tree's a Crowd
- HDU1215---七夕节 HDU(91)
- UINavigationController使用详解
- HDU2578——Dating with girls
- 怎么安装MYSQL5.0的JDBC驱动
- 扩展欧几里得算法&同余方程&模m乘法逆元详解
- 关于一些透明窗体所需的的函数
- 将双系统中的ubuntu删除以后出现no such partition grub rescue的解决方案
- Eclipse搭配开发Jsp开发环境
- UI界面类项目:非UI界面类:(第三方)
- extjs4 中使用google地图api
- 如何解决java.library.path属性在代码中设置不生效问题