【暴力模拟】UVA 1594 - Ducci Sequence

想麻烦了。这题真的那么水啊。。直接暴力模拟,1000次(看了网上的200次就能A)后判断是否全为0,否则就是LOOP;

 #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip> using namespace std;
#define INF 0x7fffffff
#define eps 1e-5
const int maxn = ;
const int maxl = ;
int a[maxn], vis[maxn];
int n;
bool Judge(int k)
{
bool zero = false;
for(int i = ; i <= n; i++)
{
if(a[i] && a[i] != k)
return ;
if(!a[i]) zero = true;
// printf("%d ", a[i]);
}
if(zero) return ;
else return ;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
memset(vis, , sizeof(vis));
memset(a, , sizeof(a));
int cnt = ;
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]);
a[n+] = a[];
int cur = , zero = ;
while(cur <= )
{
// cout << "----" <<endl; for(int i = ; i <= n; i++)
{
a[i] = abs(a[i]-a[i+]);
}
a[n+] = a[];
//cout << num << endl;
zero = ;
for(int i = ; i <= n; i++)
if(!a[i])
zero++; // cout << num << endl;
if(zero == n)
{
printf("ZERO\n");
zero = -;
break;
}
cur++;
} if(zero != -) printf("LOOP\n");
}
return ;
}
上一篇:原生ajax详解


下一篇:cookie and session