Ducci Sequence UVa1594

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <cmath>
#include <map>
#include <vector>
using namespace std;
vector<int> seq, seq2;
map<vector<int>, int> check;
int main()
{
int T;
cin >> T;
while (T--)
{
check.clear();
seq.clear();
int n;
cin >> n;
while (n--)
{
int x;
cin >> x;
seq.push_back(x);
}
check[seq] = 1;
while (true)
{
for (int i = 1; i < seq.size(); i++)
seq2.push_back(abs(seq[i] - seq[i - 1]));
seq2.push_back(abs(seq[seq.size() - 1] - seq[0]));
seq = seq2;
seq2.clear();
int flag = 1;
for (int i = 0; i < seq.size(); i++)
if (seq[i] != 0)
flag = 0;
if (flag)
{
cout << "ZERO" << endl;
goto ends;
}
if (check.count(seq))
{
cout << "LOOP" << endl;
goto ends;
}
check[seq] = 1;
}
ends: ;
}
return 0;
}