题目链接:Problem - 1714E - Codeforces
题目大意:
给定一个数组,可以进行任意次数的如下操作:
令ai=ai+ai%10;
判断是否可以将数组中所有的数变成相同的数
题目思路:
不难发现数字以1,3,5,7,9结尾的数字,在经历以上操作后就会落入0,2,4,6,8的循环,而这个循环的周期是0+2+4+6+8=20,而当中若所有数均为0或2结尾的都可以满足,判断即可
c++代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define N 1000010
#define M 998244353
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef pair<int,int> PII;
typedef pair<int,bool> PIB;
typedef pair<PII,int> PIII;
typedef pair<PII,PII> PIIPII;
typedef pair<int,vector<int> > PIV;//若俩尖括号一起则中间必须加空格
typedef long long ll;
typedef unsigned long long ull;
int t,n;
int a[N];
int main(){
cin>>t;
while(t--){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
while(a[i]%10!=0&&a[i]%10!=2){
a[i]=a[i]+a[i]%10;
}
//因为末尾为0的a[i]无法改变自己的值
if(a[i]%10==2)a[i]%=20;
}
bool f=true;
for(int i=1;i<n;i++){
if(a[i]!=a[i-1]){
f=false;
break;
}
}
if(f)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}