Ducci Sequence UVA

来源:互联网 发布:如何开通淘宝达摩盘 编辑:程序博客网 时间:2024/06/05 09:51

问题类型:数组,绝对值。

03pie’s solution for [UVA-1594]
问题链接

#include<iostream> #include<cmath>using namespace std;const int maxn = 15;int   a[maxn];int   n;inline bool reachZero(){    for(int i = 0; i < n; ++i)        if(a[i]) return false;    return true;}bool judge(){    for(int i = 0; i < 1000; ++i)    {        if(reachZero())            return true;        int tmp = a[0];        for(int j = 0; j < n - 1; ++j)        {            a[j] = abs(a[j] - a[j + 1]);        }        a[n - 1] = abs(a[n - 1] - tmp);    }    return false;}int main(){    int t;    cin >> t;    while(t--)    {        cin >> n;        for(int i = 0; i < n; ++i)            cin >> a[i];        printf("%s\n", judge() ? "ZERO" : "LOOP");    }    return 0;}
0 0