发现原来的题简单点了!?!
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
vector<int> a;
bool is_zero(int t)
{
for(int i=0;i<1009;i++){
int p=a[0],j=0,q=0;
for(;j<t-1;j++){
a[j] = abs(a[j] - a[j+1]);
if( a[j]==0 )q++;
}
if( ( a[j]=abs(a[j]-p) ) == 0 )q++;
if(q == t) return true;
}
return false;
}
int main()
{
int n;
cin>>n;
while(n--){
int t;
cin>>t;
for(int i=0;i<t;i++){
int x;
cin>>x;
a.push_back(x);
}
if(is_zero(t)) cout<<"ZERO\n";
else cout<<"LOOP\n";
a.clear();
}
return 0;
}
本文介绍了一种用于判断数组经过特定操作后是否能全部变为零值的算法实现。该算法通过多次迭代,每次迭代都将数组中的元素根据预设规则进行更新,并检查是否存在所有元素都为零的情况。如果在指定次数内数组的所有元素都能变为零,则返回 true;否则返回 false。文章通过示例代码展示了这一过程。
2410

被折叠的 条评论
为什么被折叠?



