标签:des style blog http java color
Description
Input
Output
Sample Input
6 -45 22 42 -16 -41 -27 56 30 -36 53 -37 77
1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 #define MAXN 4400 5 using namespace std; 6 int A[MAXN],B[MAXN],C[MAXN],D[MAXN]; 7 int S[MAXN*MAXN]; 8 int lower_bound1(int low,int high,int num,int a[]) 9 { 10 int mid; 11 while(low<high) 12 { 13 mid=low+(high-low)/2; 14 if(a[mid]>=num) high=mid; 15 else low=mid+1; 16 } 17 return low; 18 } 19 int upper_bound1(int low,int high,int num,int a[]) 20 { 21 int mid; 22 while(low<high) 23 { 24 mid=low+(high-low)/2; 25 if(a[mid]<=num) low=mid+1; 26 else 27 high=mid; 28 } 29 return low; 30 } 31 int main() 32 { 33 int n,i; 34 int p; 35 int cout=0; 36 int l,r,j; 37 while(scanf("%d",&n)!=EOF) 38 { 39 cout=0; 40 for(i=0;i<n;i++) 41 scanf("%d%d%d%d",&A[i],&B[i],&C[i],&D[i]); 42 p=0; 43 for(i=0;i<n;i++) 44 for(j=0;j<n;j++) 45 S[p++]=A[i]+B[j]; 46 sort(S,S+p); 47 for(i=0;i<n;i++) 48 for(j=0;j<n;j++) 49 { 50 int t=C[i]+D[j]; 51 l=lower_bound1(0,p,-t,S); 52 r=upper_bound1(0,p,-t,S); 53 cout+=(r-l); 54 } 55 printf("%d\n",cout); 56 } 57 return 0; 58 }
-36 30 -75 -46 26 -38 -10 62 -32 -54 -6 45
Sample Output
5
Hint
4 Values whose Sum is 0,布布扣,bubuko.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/angledamon/p/3861139.html