题目链接:https://vjudge.net/problem/UVA-1594
题意:对于一个n元组(a1,a2,a3,...,an),可以对于每个数求出它和下一个数的差的绝对值,得到一个新的n元组(|a1-a2|,|a2-a3|,...,|an-a1|).重复这个过程,得到的序列成为Ducci序列,例如(8, 11, 2, 7) → (3, 9, 5, 1) → (6, 4, 4, 2) → (2, 0, 2, 4) → (2, 2, 2, 2) → (0, 0, 0, 0),也有的Ducci序列最终会循环。输入n元组(3<=n<=15),你的人物是判断它最终会变成0还是会循环。输入保证最多1000步就会变成0或者循环。
水题水解呗,这题的数据很水,说是1000,其实100都能过,直接用数组模拟就行了。
#include <stdio.h>
#include <math.h>
int main() {
int N, n;
bool flag;
int a[20], b[20];
scanf("%d",&N);
while(N--) {
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%d",&a[i]);
int T = 100;
while(T--) {
flag = false;
for(int i = 0; i < n; i++) {
b[i] = abs(a[i%n] - a[(i+1)%n]);//这不很巧妙
}
for(int i = 0; i < n; i++) {
a[i] = b[i];
}
for(int i = 0; i < n; i++) {
if(a[i]) {
flag = true;
break;
}
}
if(!flag) {
printf("ZERO\n");
break;
}
}
if(flag) printf("LOOP\n");
}
return 0;
}