Ducci Sequence
.
.
题意:给出一组数列,每一次变换对应的 ai = abs(a[i]-a[i+1]),数列a组成一个换,问最后会是一个循环还是会变成一个0序列。
.
.
解法:直接暴力多次,如果不是0序列那么一定是循环
.
.
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int tt, n, a[2][1000];
int main() {
cin >> tt;
while (tt--) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[0][i];
a[0][n+1] = a[0][1];
a[0][0] = a[0][n];
int k = 0;
for (int all = 1; all <= 10000; all++) {
k = 1-k;
for (int i = 1; i <= n; i++)
a[k][i] = abs(a[1-k][i]-a[1-k][i+1]);
a[k][n+1] = a[k][1];
a[k][0] = a[k][n];
}
bool flag = true;
for (int i = 1; i <= n; i++) if (a[k][i] != 0) flag = false;
if (flag) cout << "ZERO" << endl;
else cout << "LOOP" << endl;
}
}