Test instructions
Give the number of N, and M, ask the number of N to choose two numbers x, y to make the method of x+y<=m how many kinds, xy order independent.
Ideas:
Preprocessing all the numbers, the default x<y to enumerate.
For an x, the y that satisfies the condition must be within the [x,m-y] range. Even if there are many numbers.
Then count the equal cases separately.
Code:
#include "cstdlib" #include "Cstdio" #include "CString" #include "Cmath" #include "queue" #include "algorithm" #include " iostream "#include" map "using namespace std; #define LL __int64int V[1000002],a[25448];int Main () { int n,s; while (scanf ("%d%d", &n,&s)!=-1) { memset (v,0,sizeof (v)); for (int i=0;i<n;i++) { int x; scanf ("%d", &x); a[i]=x; v[x]++; } for (int i=0;i<=1000000;i++) v[i]+=v[i-1]; Sort (a,a+n); int ans=0; for (int i=0;i<n;i++) { if (A[I]>=S/2) break; Ans+=v[s-a[i]]-v[a[i]]; } for (int i=1;i<=1000000;i++) { int tep=v[i]-v[i-1]; if (I>S/2) break; if (!tep) continue; ans+=tep* (tep-1)/2; } printf ("%d\n", ans); } return 0;}
[Ideas] poj 3663 Costume Party