原题链接

翻译:

给出一个长度为n的数组,对每个元素a[i],可以执行 a[i] = a[i] + a[i] mod 10 无限次。问可不可以构造出一个所有元素相等的数组。

思路:

找规律即可。手算模拟几次发现,除了末尾为5或0的数字需要特判。其他数字在模20后可以统统分成两组,两个集合是对立的,根据这个去check即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 200005
#define MAXM 200005
typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
#define rep(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for(int i = x; i >= y; i--)
#define pb emplace_back
ll read() {
ll x=0,f=1;char ch;
do{ch=getchar();if(ch=='-') f=-1;} while(ch<'0'||ch>'9');
do{x=x*10+ch-48;ch=getchar();} while(ch>='0'&&ch<='9');
return x*f;
}
int n;
int a[MAXN];
bool vis[25];

void init() {
for (int i = 0; i <= 20; i++) {
vis[i] = false;
}
}

bool check() {
map<int, int> cnt;
for (int i = 1; i <= n; i++) {
if (a[i] % 10 != 0 && a[i] % 10 != 5) {
return false;
}
}
sort(a + 1, a + 1 + n);
if (a[n] - a[1] == 5 && a[1] % 10 == 5 || a[1] == a[n]) {
return true;
}
return false;
}

void solve() {
n = read();
init();
bool check_flag = false;
for (int i = 1; i <= n; i++) {
a[i] = read();
if (a[i] % 10 == 5 || a[i] % 10 == 0) {
check_flag = true;
}
vis[a[i] % 20] = true;
}
if (check_flag) {
check_flag = check();
if (check_flag) {
puts("YES");
}
else {
puts("NO");
}
return;
}
bool group1 = vis[1] || vis[2] || vis[4] || vis[8] || vis[16] || vis[13] || vis[17] || vis[19];
bool group2 = vis[3] || vis[7] || vis[9] || vis[11] || vis[6] || vis[12] || vis[14] || vis[18];
if (group1 && group2) {
puts("NO");
}
else {
puts("YES");
}
}

int main() {
int T;
T = read();
for (int i = 1; i <= T; i++) {
solve();
}

return 0;
}