Add Modulo 10 (规律循环节,代码实现细节)

题目描述

You are given an array of $ n $ integers $ a_1, a_2, \dots, a_n $

You can apply the following operation an arbitrary number of times:

  • select an index $ i $ ( $ 1 \le i \le n $ ) and replace the value of the element $ a_i $ with the value $ a_i + (a_i \bmod 10) $ , where $ a_i \bmod 10 $ is the remainder of the integer dividing $ a_i $ by $ 10 $ .

For a single index (value $ i $ ), this operation can be applied multiple times. If the operation is applied repeatedly to the same index, then the current value of $ a_i $ is taken into account each time. For example, if $ a_i=47 $ then after the first operation we get $ a_i=47+7=54 $ , and after the second operation we get $ a_i=54+4=58 $ .

Check if it is possible to make all array elements equal by applying multiple (possibly zero) operations.

For example, you have an array $ [6, 11] $ .

  • Let’s apply this operation to the first element of the array. Let’s replace $ a_1 = 6 $ with $ a_1 + (a_1 \bmod 10) = 6 + (6 \bmod 10) = 6 + 6 = 12 $ . We get the array $ [12, 11] $ .
  • Then apply this operation to the second element of the array. Let’s replace $ a_2 = 11 $ with $ a_2 + (a_2 \bmod 10) = 11 + (11 \bmod 10) = 11 + 1 = 12 $ . We get the array $ [12, 12] $ .

Thus, by applying $ 2 $ operations, you can make all elements of an array equal.

输入格式

The first line contains one integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases. What follows is a description of each test case.

The first line of each test case contains one integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the size of the array.

The second line of each test case contains $ n $ integers $ a_i $ ( $ 0 \le a_i \le 10^9 $ ) — array elements.

It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .

输出格式

For each test case print:

  • YES if it is possible to make all array elements equal;
  • NO otherwise.

You can print YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer) .

样例 #1

样例输入 #1

10
2
6 11
3
2 18 22
5
5 10 5 10 5
4
1 2 4 8
2
4 5
3
93 96 102
2
40 6
2
50 30
2
22 44
2
1 5

样例输出 #1

Yes
No
Yes
Yes
No
Yes
No
No
Yes
No

提示

The first test case is clarified above.

In the second test case, it is impossible to make all array elements equal.

In the third test case, you need to apply this operation once to all elements equal to $ 5 $ .

In the fourth test case, you need to apply this operation to all elements until they become equal to $ 8 $ .

In the fifth test case, it is impossible to make all array elements equal.

In the sixth test case, you need to apply this operation to all elements until they become equal to $ 102 $ .


打表找循环节。

我的:

/*
1 2 4 8 16
3 6 12 14 18
*/
void solve(){cin>>n;set<int>st;bool ok = 1;bool A = 0;// 1bool B = 0;// 3bool C = 0;// 5fo(i,1,n){int x;cin>>x;int t = x+x%10;if(t%5==0){if(!C){C=1;st.insert(t);}else{if(st.find(t)!=st.end());else ok = 0;}}t %= 20;if(t == 1 || t == 2 || t == 4 || t == 8 || t == 16){if(!A){A=1;st.insert(1);}}if(t == 3 || t == 6 || t == 12 || t == 14 || t == 18){if(!B){B=1;st.insert(3);}}}if(st.size()!=1){ok = 0;}cout<<(ok ? "YES" : "NO")<<endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 300005;int a[N];
int main() {int _;scanf("%d", &_);while (_--) {int n;scanf("%d", &n);vector<int> b;set<int> c;for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);if (a[i] % 10 == 5)b.push_back(a[i] + 5);else if (a[i] % 10 == 0)b.push_back(a[i]);else {int x = a[i];while (x % 10 != 6) {x += x % 10;}c.insert(x % 20);}}if (b.size() > 0) {int ok = b.size() == n;for (auto x : b)if (x != b[0]) ok = 0;puts(ok ? "YES" : "NO");} else {puts(c.size() == 1 ? "YES" : "NO");}}return 0;
}
/***    author:  tourist*    created: 01.08.2022 17:43:24
**/
#include <bits/stdc++.h>using namespace std;#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endifint main() {ios::sync_with_stdio(false);cin.tie(0);int tt;cin >> tt;while (tt--) {int n;cin >> n;vector<int> a(n);bool any = false;for (int i = 0; i < n; i++) {cin >> a[i];while (a[i] % 10 != 0 && a[i] % 10 != 2) {a[i] += a[i] % 10;}any |= (a[i] % 10 == 0);}if (any) {cout << (a == vector<int>(n, a[0]) ? "Yes" : "No") << '\n';continue;}int val = a[0] % 20;bool ok = true;for (int i = 0; i < n; i++) {ok &= (a[i] % 20 == val);}cout << (ok ? "Yes" : "No") << '\n';}return 0;
}

Add Modulo 10 (规律循环节,代码实现细节)相关推荐

  1. E. Add Modulo 10(规律)

    E. Add Modulo 10(规律) 可以看出末位为1.3.6.7.9 最终会进入到2.4.8.6的循环. 2 + 4 + 8 + 6 = 20 2+4+8+6=20 2+4+8+6=20,这个周 ...

  2. Codeforces Round #811 (Div. 3) E. Add Modulo 10

    E. Add Modulo 10 题意 给你n个数,你现在可以执行一个操作,假如对a[i]执行操作:a[i] = a[i] + (a[i] % 10),问你能不能够最后让所有的数都相等. 思路 首先我 ...

  3. codeforces:E. Add Modulo 10【状态压缩 + 找规律】

    分析 分类讨论,进行操作 [5,0]落回0 其余落到2 然后就停止 分两类 如果是第一类,必须是同一个0结尾才行 如果第二类,必须%20相同才行 ac code import sys input = ...

  4. Codeforces Round #811 (Div. 3) E Add Modulo 10

    原题链接:Problem - E - Codeforces 题目描述: You are given an array of nn integers a1,a2,-,ana1,a2,-,an You c ...

  5. 【蓝桥杯】有理数的循环节

    有理数的循环节 1 / 7 = 0.142857142 ⋯ ⋯ 1/7 = 0.142857142 \cdots\cdots 1/7=0.142857142⋯⋯ 是个无限循环小数. 任何有理数都可以表 ...

  6. 循环节长度以及循环节

    循环节长度 两个整数做除法,有时会产生循环小数,其循环部分称为:循环节.  比如,11/13=6=>0.846153846153-.. 其循环节为[846153] 共有6位. 这是一道蓝桥杯的题 ...

  7. 2018年东北农业大学春季校赛 K wyh的数列【数论/斐波那契数列大数取模/循环节】...

    链接:https://www.nowcoder.com/acm/contest/93/K 来源:牛客网 题目描述 wyh学长特别喜欢斐波那契数列,F(0)=0,F(1)=1,F(n)=F(n-1)+F ...

  8. hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节)

    Problem - 3374 KMP求循环节. http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html 循环节推导的证明相当的好,这 ...

  9. 输出1/n(是循环小数的,只输出第一个循环节)

    Input 第一行整数T,表示测试组数.后面T行,每行一个整数 n (1<=|n|<=10^5). Output 输出1/n. (是循环小数的,只输出第一个循环节). Sample Inp ...

最新文章

  1. vim ctags使用方法
  2. centos7设置密码策略_Linux系统设置复杂密码策略方法总结
  3. LeetCode 90子集Ⅱ91解码方法
  4. android 导入离线地图,Android, 离线地图-2
  5. MFC 最详细入门教程
  6. P5441 【XR-2】伤痕
  7. mac linux 引导分区,Paragon ExtFS For Mac v10.0.829 | Linux分区数据读写驱动 _ 黑苹果乐园...
  8. 机器学习-29-Pointer Network(指针网络)
  9. svn 文件夹没有绿勾红感叹号图标
  10. 整合dubbo报错严重 Exception sending context initialized event to listener instance of class 解决
  11. CSAPP:BombLab 详细解析
  12. gym:Problem B Bless You Autocorrect!(字典树+最短路)
  13. python大数据毕业设计题目100例
  14. 4、基本命令-系统管理
  15. pc端客户端爬虫_FIddler+Proxifer工具对windows PC客户端进行抓包
  16. 【CicadaPlayer】播放器状态
  17. 概率论与数理统计系列笔记之第四章——大数定理与中心极限定理
  18. SurfaceFlinger服务的启动
  19. 95后阿里P7晒出工资单:狠补了这个,真香....
  20. html 手机语音聊天,华为手机打开这个功能,语音通话一键实时翻译,能直接和老外交流...

热门文章

  1. mac 中通过终端快速用 VsCode 打开当前目录,出现 command not found: code 问题解决方案
  2. 传奇假人自动上线_传奇商业脚本 各种M2防假人脚本大集合 传奇私服脚本
  3. 解决方法:STM32使用cJSON解析数据失败
  4. Android13 App 预装详解
  5. pytorch替换numpy中的一些组件 //转载请注明来源
  6. RT5350 openwrt添加Reset按键,实现短按重启系统,长按复位系统
  7. python 实战之模仿开发QQ聊天软件(一)登录GUI设计
  8. Android - ReactNative Debug 技巧
  9. Fluke TiS60+红外热像仪 福禄克TiS60+热成像仪
  10. Unity中 Prefab导出FBX