标签:show als first splay 整数 return out 下标 none
第1行,1个数N,N为数组的长度(4 <= N <= 1000) 第2 - N + 1行:A[i](-10^9 <= A[i] <= 10^9)
如果可以选出4个数,使得他们的和为0,则输出"Yes",否则输出"No"。
5 -1 1 -5 2 4
Yes
1 #include<stdio.h> 2 #include<iostream> 3 #define ULL unsigned long long 4 #define maxn 1000007 5 using namespace std; 6 7 // 上面maxn那里我一开始设的是100007,结果TLE qwq 8 9 struct data{ ULL val,pos; }sum[maxn]; 10 int m,n,arr[maxn]; 11 12 struct edge{ ULL val,pos; int from; }e[maxn*4]; 13 int tot,first[maxn]; 14 15 bool noequ(ULL A,ULL B){ 16 return (A/10000 != B/10000) && (A%10000 != B%10000); 17 } 18 19 bool check(ULL val,ULL pos){ 20 int w = val%maxn; 21 for(int i = first[w];i;i = e[i].from){ 22 if(e[i].val == val && noequ(e[i].pos,pos)) return true; 23 }return false; 24 } 25 26 void insert(int pos1,int pos2,int suuum){ 27 if(pos1 > pos2) swap(pos1,pos2); 28 ULL val = (ULL)(suuum+1e9); 29 ULL kcode = pos1*10000+pos2; 30 31 if(check(val,kcode)) return; 32 33 int w = val%maxn; 34 35 tot++; e[tot].from = first[w]; 36 e[tot].val = val; e[tot].pos = kcode; 37 first[w] = tot; 38 sum[++m].val = val; 39 sum[m].pos = kcode; 40 } 41 42 int main(){ 43 scanf("%d",&n); 44 45 for(int i = 1;i <= n;i++) 46 scanf("%d",&arr[i]); 47 48 for(int i = 1;i <= n;i++) 49 for(int j = i+1;j <= n;j++) 50 insert(i,j,arr[i]+arr[j]); 51 52 // for(int i = 1;i <= m;i++) printf("%I64u %I64u\n",sum[i].val,sum[i].pos); 53 // 54 // cout << "Hash:" << endl; 55 // 56 // for(int i = 1;i <= tot;i++) printf("%I64u %I64u\n",e[i].val,e[i].pos); 57 58 for(int i = 1;i <= m;i++){ 59 if(check(2e9-sum[i].val,sum[i].pos)){ 60 cout << "Yes"; 61 return 0; 62 } 63 } 64 65 cout << "No"; 66 67 return 0; 68 }
标签:show als first splay 整数 return out 下标 none
原文地址:http://www.cnblogs.com/Chorolop/p/7788962.html