Codeforces Round #811 (Div. 3)

比赛链接

Codeforces Round #811 (Div. 3)

E. Add Modulo 10

给出 n 个数,每次可以将其中一个数加上其对 10 的模数,问最后所有数能否相等

解题思路

思维

可以发现,如果同时出现对 10 的模数为 50 跟其他模数的情况肯定无法相等,所以需要特判对 10 的模数为 50 情况,其他情况由于其加上都是 2,4,8,6 一个循环,而且如果所有数能相等的话,把这些数变为对 10 的模数为 2 也不会对判断有影响,转化后判断所有数对 20 的模数是否相等即可

时间复杂度:O(n)

代码

// Problem: E. Add Modulo 10 // Contest: Codeforces - Codeforces Round #811 (Div. 3) // URL: https://codeforces.com/contest/1714/problem/E // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) // %%%Skyqwq #include <bits/stdc++.h> //#define int long long #define help {cin.tie(NULL); cout.tie(NULL);} #define pb push_back #define fi first #define se second #define mkp make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; } template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; } template <typename T> void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar(); x *= f; } const int N=2e5+5; int t,n,a[N]; int main() { for(cin>>t;t;t--) { cin>>n; bool fl[2]={0}; for(int i=1;i<=n;i++) { cin>>a[i]; if(a[i]%10==5||a[i]%10==0) { if(a[i]%10==5)a[i]+=5; fl[0]=true; } else fl[1]=true; } bool f=true; if(fl[0]) { if(fl[1])f=false; else { for(int i=2;i<=n;i++) if(a[i]!=a[i-1])f=false; } } else { for(int i=1;i<=n;i++) { while(a[i]%10!=2)a[i]+=a[i]%10; a[i]%=20; } for(int i=2;i<=n;i++) if(a[i]!=a[i-1])f=false; } puts(f?"Yes":"No"); } return 0; }

__EOF__

本文作者acwing_zyy
本文链接https://www.cnblogs.com/zyyun/p/16574443.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   zyy2001  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示