AcWing 5618. 全球变暖
原题链接
简单
作者:
ywt51
,
2024-12-03 14:17:01
,
所有人可见
,
阅读 1
#include <bits/stdc++.h>
using namespace std;
const int N = 24;
int n, a[N], b[N], T;
int main()
{
while (cin >> n, n)
{
for (int i = 0; i < n; ++ i) cin >> a[i];
for (int i = 0; i < n-1; ++ i) b[i] = a[i+1] - a[i];
if (n == 1)
{
cout << 0 << endl;
continue;
}
for (int len = 1; len < n; ++ len) //枚举周期的长度
{
bool f = 1;//第一个周期后面的数字和len位置数比较
for (int i = len; i < n-1; ++ i)
if (b[i] != b[i%len])
{
f = 0;
break;
}
if (f)
{
cout << len << endl;
break;
}
}
}
return 0;
}