2 have done, put 1 to fill.
Test instructions gives N and K, and the number of N. is the n number to find the two number x, Y. Make x+y=k.
Calculate all the possibilities. When X0+y0=k. X1+y1=k. Must have unequal. X0!=x1 or Y0!=y1.
For example
4 4
2 2 2 2
The correct output should be 1.
I was sort of, went heavy, and then two points. It seems that many people are using the pointers.
Forget the STL's two-point return subscript function, the mood is not good, too lazy to check, hand hit two points.
#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># include<bitset> #include <vector> #include <cmath> #define INF 0x7fffffff#define EPS 1e-8#define LL Long Long#define PI 3.141592654#define CLR (A, B) memset (A,b,sizeof (a)) #define for (I,A,B) for (int i=a;i<b;i++) #define For_ (I,A,B) for (int. i=a;i>=b;i--) #define SF scanf#define PF Printf#define All (v) (v). Begin (), (v). End () #define Acfun Std::ios::sync_with_stdio (False) #define SIZE (100000 +2) #define MOD 1000000007using namespace std;int binsearch (int *a, int L,int R,int key) {while (l<=r) {int m= (L+R) >>1; if (A[m]==key) return m; else if (A[m]>key) r=m-1; else l=m+1; } return-1;} int main () {int t; SF ("%d", &t); while (t--) {int n,m; SF ("%d%d", &n,&M); int a[size]; for (I,0,n) SF ("%d", &a[i]); Sort (a,a+n); int cnt =unique (a,a+n)-A; int ans=0; for (i,0,cnt) {if (A[i]<=m&&binsearch (a,0,cnt-1,m-a[i))!=-1) ans++; } PF ("%d\n", ans); }}
HDU 2578 Dating with girls (1)