想麻烦了。这题真的那么水啊。。直接暴力模拟,1000次(看了网上的200次就能A)后判断是否全为0,否则就是LOOP;
1 #include <iostream> 2 #include <sstream> 3 #include <cstdio> 4 #include <cstring> 5 #include <cmath> 6 #include <string> 7 #include <vector> 8 #include <set> 9 #include <cctype> 10 #include <algorithm> 11 #include <cmath> 12 #include <deque> 13 #include <queue> 14 #include <map> 15 #include <stack> 16 #include <list> 17 #include <iomanip> 18 19 using namespace std; 20 #define INF 0x7fffffff 21 #define eps 1e-5 22 const int maxn = 20; 23 const int maxl = 1010; 24 int a[maxn], vis[maxn]; 25 int n; 26 bool Judge(int k) 27 { 28 bool zero = false; 29 for(int i = 1; i <= n; i++) 30 { 31 if(a[i] && a[i] != k) 32 return 0; 33 if(!a[i]) zero = true; 34 // printf("%d ", a[i]); 35 } 36 if(zero) return 1; 37 else return 0; 38 } 39 40 int main() 41 { 42 int T; 43 scanf("%d", &T); 44 while(T--) 45 { 46 memset(vis, 0, sizeof(vis)); 47 memset(a, 0, sizeof(a)); 48 int cnt = 0; 49 scanf("%d", &n); 50 for(int i = 1; i <= n; i++) 51 scanf("%d", &a[i]); 52 a[n+1] = a[1]; 53 int cur = 1, zero = 0; 54 while(cur <= 200) 55 { 56 // cout << "----" <<endl; 57 58 for(int i = 1; i <= n; i++) 59 { 60 a[i] = abs(a[i]-a[i+1]); 61 } 62 a[n+1] = a[1]; 63 //cout << num << endl; 64 zero = 0; 65 for(int i = 1; i <= n; i++) 66 if(!a[i]) 67 zero++; 68 69 // cout << num << endl; 70 if(zero == n) 71 { 72 printf("ZERO "); 73 zero = -1; 74 break; 75 } 76 cur++; 77 } 78 79 if(zero != -1) printf("LOOP "); 80 } 81 return 0; 82 }