标签:out value while absolute abs adr return std name
Input
Output
Sample Input
6 -45 22 42 -16 -41 -27 56 30 -36 53 -37 77 -36 30 -75 -46 26 -38 -10 62 -32 -54 -6 45
Sample Output
5
Hint
1 #include <iostream> 2 using namespace std; 3 #include<string.h> 4 #include<set> 5 #include<stdio.h> 6 #include<math.h> 7 #include<queue> 8 #include<map> 9 #include<algorithm> 10 #include<cstdio> 11 #include<cmath> 12 #include<cstring> 13 #include <cstdio> 14 #include <cstdlib> 15 #include<cstring> 16 int a[4010],b[4010],c[4010],d[4010]; 17 int a1[16000000],b1[16000000]; 18 set<int>TM; 19 int main() 20 { 21 int t; 22 cin>>t; 23 for(int i=0;i<t;i++) 24 cin>>a[i]>>b[i]>>c[i]>>d[i]; 25 int add=0; 26 for(int i=0;i<t;i++) 27 for(int j=0;j<t;j++) 28 { 29 b1[add]=(a[i]+b[j]); 30 a1[add++]=c[i]+d[j]; 31 } 32 sort(b1,b1+add); 33 int sum=0; 34 for(int i=0;i<add;i++) 35 { 36 int tou=0,wei=add,zhongjian; 37 while(tou<=wei) 38 { 39 zhongjian=(tou+wei)/2; 40 if(a1[i]+b1[zhongjian]==0) 41 { 42 sum++; 43 for(int j=zhongjian-1;j>=0;j--) 44 { 45 if(b1[j]!=b1[j+1]) 46 break; 47 else 48 sum++; 49 } 50 for(int j=zhongjian+1;j<add;j++) 51 { 52 if(b1[j]!=b1[j-1]) 53 break; 54 else 55 sum++; 56 } 57 break; 58 } 59 else if(a1[i]+b1[zhongjian]<0) 60 tou=zhongjian+1; 61 else 62 wei=zhongjian-1; 63 } 64 } 65 cout<<sum<<endl; 66 return 0; 67 }
4 Values whose Sum is 0 poj2785
标签:out value while absolute abs adr return std name
原文地址:http://www.cnblogs.com/dulute/p/7289192.html