https://vjudge.net/contest/185301#problem/B
用队列记录,set的不重复性来判断
1 //#include<bits/stdc++.h> 2 #include<stdio.h> 3 #include<string.h> 4 #include<math.h> 5 #include<iostream> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<queue> 9 #include<vector> 10 #include<string> 11 #include<set> 12 #include<cctype> 13 #include<sstream> 14 #define mem(a) memset(a,0,sizeof(a)) 15 #define LL long long 16 #define ull unsigned long long 17 #define inf 0x3f3f3f3f 18 using namespace std; 19 const int N=998244353; 20 int n,k; 21 char s[105],ss[105]; 22 int a[10500],b[105]; 23 LL f[1005][2010][2]; 24 int abs(int a) 25 { 26 if(a<0) return -a; 27 return a; 28 } 29 int main() 30 { 31 int t,v,c; 32 scanf("%d",&t); 33 while(t--) 34 { 35 scanf("%d",&n); 36 queue<int>q; 37 set<int>s; 38 int flag=0; 39 for(int i=1;i<=n;i++) 40 { 41 scanf("%d",&v); 42 q.push(v); 43 } 44 for(int i=0;i<1000;i++) 45 { 46 for(int j=1;j<=n;j++) 47 { 48 if(j==1) 49 { 50 int u=q.front(); 51 int k=q.back(); 52 c=abs(u-k); 53 } 54 int u=q.front(); 55 q.pop(); 56 if(j<n) 57 { 58 int k=q.front(); 59 q.push(abs(u-k)); 60 s.insert(abs(u-k)); 61 } 62 if(j==n) 63 { 64 q.push(c); 65 s.insert(c); 66 } 67 } 68 if(s.size()==1) 69 { 70 flag=1; 71 break; 72 } 73 s.clear();//!! 74 } 75 while(!q.empty()) 76 { 77 q.pop(); //!! 78 } 79 if(flag==1) printf("ZERO "); 80 else printf("LOOP "); 81 } 82 return 0; 83 }