http://acm.bnu.edu.cn/v3/contest_show.php?cid=5772#problem/L
输入n元组(3<=n<=15),你的任务是判断它最终变成0还是循环。输入保证最多1000步就会变成0或者循环。
只要每步判断下是否全0即可,因为只输出ZERO/LOOP即可..
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <map> #include <iostream> #include <sstream> #include <algorithm> using namespace std; #define RD(x) scanf("%d",&x) #define RD2(x,y) scanf("%d%d",&x,&y) #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define clr0(x) memset(x,0,sizeof(x)) #define clr1(x) memset(x,-1,sizeof(x)) #define eps 1e-9 const double pi = acos(-1.0); typedef long long LL; const int inf = 1000000000; const int maxn = 1e5+5; //LL l,r,x; typedef pair<int,int> p2; int n; int a[20]; bool check() { for(int i = 0;i < n;++i){ if(a[i]) return false; } return true; } int main() { int _; RD(_); while(_--){ RD(n); for(int i = 0;i < n;++i){ RD(a[i]); } bool flag = false; int cnt = 0; while(cnt < 1000 && !flag){ cnt++; flag = check(); a[n] = a[0]; for(int i = 0;i < n;++i) a[i] = abs(a[i] - a[i+1]); } printf("%s\n",flag?"ZERO":"LOOP"); } return 0; }