【题解】Toyota Programming Contest 2024#12(AtCoder Beginner Contest 384)
总体情况
感觉这次在起飞。
20 分钟后就在罚坐。
A - aaaadaa
题目描述
给定一个长度为 \(N\) 的字符串 \(S\) ,由小写英文字母以及小写英文字母 \(c_1\) 和 \(c_2\) 组成。
查找将 \(S\) 中所有不属于 \(c_1\) 的字符替换为 \(c_2\) 后得到的字符串。
思路分析
直接模拟。
代码
// Problem: A - aaaadaa // Contest: AtCoder - Toyota Programming Contest 2024#12(AtCoder Beginner Contest 384) // URL: https://atcoder.jp/contests/abc384/tasks/abc384_a // Memory Limit: 1024 MB // Time Limit: 2000 ms #include<bits/stdc++.h> using namespace std; #define endl '\n' //#define int long long namespace gtx{ // Fast IO void read(int &x){ x = 0;int h = 1;char tmp; do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp)); while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar(); x*=h; } void read(char &x){do{x=getchar();}while(x==' '||x=='\n'||x=='\r');} void write(char x){putchar(x);} void write(int x){ if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0; do{st[++tot]=x%10,x/=10;} while(x); while(tot){putchar(st[tot--]+'0');} } void write(int x,char y){write(x);write(y);} #ifndef int void read(long long &x){ x = 0;int h = 1;char tmp; do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp)); while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar(); x*=h; } void write(long long x){ if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0; do{st[++tot]=x%10,x/=10;} while(x); while(tot){putchar(st[tot--]+'0');} } void write(long long x,char y){write(x);write(y);} #endif signed main(){ int n; char a,b; string s; cin >> n >> a >> b >> s; for(char i:s){ if(i==a) cout << a; else cout <<b; } return 0; } } signed main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); // ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int T = 1; // gtx::read(T); while(T--) gtx::main(); return 0; }
B - ARC Division
题目描述
AtCoder 常规竞赛 (ARC) 分为两个部分。
- 在 ARC Div. \(1\) 中,竞赛开始时评分在 \(1600\) 和 \(2799\) 之间(含)的参与者需要更新评分。
- 在 ARC Div. \(2\) 中,竞赛开始时评分在 \(1200\) 和 \(2399\) 之间(含)的参与者需要更新评分。
Takahashi 决定参加 \(N\) ARC。
最初,他的评分为 \(R\) 。
第 \(i\) 个 \((1\leq i\leq N)\) ARC 是 Div. \(D _ i\) ,他在该比赛中的表现用整数 \(A _ i\) 表示。
如果他在第 \(i\) -th ARC 中需要更新评级,则让 \(T\) 成为他在该比赛开始时的评级。然后,比赛结束后,他的评级变为 \(T+A _ i\) 。
如果他不需要更新评级,则他的评级不会改变。
ARC 的评级更新在比赛结束后立即进行,他是否需要在下一场比赛中进行评级更新取决于更新后的评级。
完成 \(N\) ARC 后查找他的评级。
除了这些 \(N\) ARC 之外,他不参加任何比赛,他的评级不会以其他方式发生变化。
思路分析
直接模拟即可。
代码
// Problem: B - ARC Division // Contest: AtCoder - Toyota Programming Contest 2024#12(AtCoder Beginner Contest 384) // URL: https://atcoder.jp/contests/abc384/tasks/abc384_b // Memory Limit: 1024 MB // Time Limit: 2000 ms #include<bits/stdc++.h> using namespace std; #define endl '\n' #define int long long namespace gtx{ // Fast IO void read(int &x){ x = 0;int h = 1;char tmp; do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp)); while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar(); x*=h; } void read(char &x){do{x=getchar();}while(x==' '||x=='\n'||x=='\r');} void write(char x){putchar(x);} void write(int x){ if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0; do{st[++tot]=x%10,x/=10;} while(x); while(tot){putchar(st[tot--]+'0');} } void write(int x,char y){write(x);write(y);} #ifndef int void read(long long &x){ x = 0;int h = 1;char tmp; do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp)); while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar(); x*=h; } void write(long long x){ if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0; do{st[++tot]=x%10,x/=10;} while(x); while(tot){putchar(st[tot--]+'0');} } void write(long long x,char y){write(x);write(y);} #endif signed main(){ int n,r; cin >>n >> r; for(int i = 1;i<=n;i++){ int d,a; cin >> d >>a; if(d==1){ if(1600<=r&&r<=2799) r+=a; }else if(d==2){ if(1200<=r&&r<=2399) r+=a; } } cout << r; return 0; } } signed main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); // ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int T = 1; // gtx::read(T); while(T--) gtx::main(); return 0; }
C - Perfect Standings
题目描述
Takahashi 决定举办一次编程竞赛。
竞赛包含五道题目:A、B、C、D、E,得分分别为 \(a\) 、 \(b\) 、 \(c\) 、 \(d\) 、 \(e\) 。
共有 \(31\) 名参赛者,他们都至少解决了一道题目。
更具体地说,对于字符串 ABCDE
的每个非空子序列(不一定连续),都有一个以该子序列命名的参赛者,他解决了与其名字中字母对应的题目,而没有解决其他题目。
例如,参赛者 A 只解决了题目 A,参赛者 BCE 解决了题目 B、C 和 E。
按得分从大到小的顺序打印参赛者的姓名。参与者获得的分数是他们所解决问题的分数的总和。
如果两个参与者获得的分数相同,则首先打印名字在字典中较小的参与者。
“字典中较小”是什么意思?
简而言之,“字典中较小”是指单词在字典中出现的顺序。
更准确地说,对于由大写英文字母组成的不同字符串 \(S,T\) ,如果满足以下任一条件,则 \(S\) 在字典中小于 \(T\) :
- \(S\) 的长度 \(|S|\) 小于 \(T\) 的长度,并且 \(T\) 的前 \(|S|\) 个字符与 \(S\) 匹配。
- 存在一个整数 \(1\leq i\leq\min\{ |S|,|T|\}\) ,它同时满足以下两个条件:
- 对于每个整数 \(j\) ,其值为 \(1\leq j\lt i\) , \(S\) 的第 \(j\) 个字符等于 \(T\) 的第 \(j\) 个字符。
- \(S\) 的第 \(i\) 个字符按字母顺序小于 \(T\) 的第 \(i\) 个字符。
例如,如果 \(S=\) AB
和 \(T=\) ABC
,则第一个条件成立,因此 \(S\) 按字典顺序小于 \(T\) 。如果 \(S=\) ABD
且 \(T=\) ACD
,则第二个条件对 \(i=2\) 成立,因此 \(S\) 按字典顺序小于 \(T\) 。
思路分析
暴力搜索,然后放入一个 pair<int,string>
排序就行。
代码
// Problem: C - Perfect Standings // Contest: AtCoder - Toyota Programming Contest 2024#12(AtCoder Beginner Contest 384) // URL: https://atcoder.jp/contests/abc384/tasks/abc384_c // Memory Limit: 1024 MB // Time Limit: 2000 ms #include<bits/stdc++.h> using namespace std; #define endl '\n' #define int long long namespace gtx{ // Fast IO void read(int &x){ x = 0;int h = 1;char tmp; do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp)); while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar(); x*=h; } void read(char &x){do{x=getchar();}while(x==' '||x=='\n'||x=='\r');} void write(char x){putchar(x);} void write(int x){ if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0; do{st[++tot]=x%10,x/=10;} while(x); while(tot){putchar(st[tot--]+'0');} } void write(int x,char y){write(x);write(y);} #ifndef int void read(long long &x){ x = 0;int h = 1;char tmp; do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp)); while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar(); x*=h; } void write(long long x){ if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0; do{st[++tot]=x%10,x/=10;} while(x); while(tot){putchar(st[tot--]+'0');} } void write(long long x,char y){write(x);write(y);} #endif vector<pair<int,string>> v; string now; int a[6]; void dfs(char tmp,int s){ if(tmp=='F'){ if(now=="") return; v.push_back({-s,now}); return; } dfs(tmp+1,s); now+=tmp;s+=a[tmp-'A']; dfs(tmp+1,s); now.erase(--now.end()); s-=a[tmp-'A']; } signed main(){ cin >>a[0] >>a[1 ] >> a[2] >> a[3] >> a[4]; dfs('A',0); sort(v.begin(),v.end()); for(auto i:v) cout << i.second <<endl; return 0; } } signed main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); // ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int T = 1; // gtx::read(T); while(T--) gtx::main(); return 0; }
D - Repeated Sequence
题目描述
给定一个无限序列 \(A=(A _ 1,A _ 2,A _ 3,\dotsc)\) ,其周期为 \(N\) ,前 \(N\) 项 \(A _ 1,A _ 2,\dotsc,A _ N\) 。
确定此无限序列是否存在一个非空的连续子序列,其和为 \(S\) 。
这里,当对每个整数 \(i > N\) 都有 \(A _ i=A _ {i-N}\) 时,无限序列 \(A\) 的周期为 \(N\) 。
思路分析
首先对总和取模。
否则直接枚举区间,发现具有单调性,直接双指针。
代码
// Problem: D - Repeated Sequence // Contest: AtCoder - Toyota Programming Contest 2024#12(AtCoder Beginner Contest 384) // URL: https://atcoder.jp/contests/abc384/tasks/abc384_d // Memory Limit: 1024 MB // Time Limit: 2000 ms #include<bits/stdc++.h> using namespace std; #define endl '\n' #define int long long namespace gtx{ // Fast IO void read(int &x){ x = 0;int h = 1;char tmp; do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp)); while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar(); x*=h; } void read(char &x){do{x=getchar();}while(x==' '||x=='\n'||x=='\r');} void write(char x){putchar(x);} void write(int x){ if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0; do{st[++tot]=x%10,x/=10;} while(x); while(tot){putchar(st[tot--]+'0');} } void write(int x,char y){write(x);write(y);} #ifndef int void read(long long &x){ x = 0;int h = 1;char tmp; do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp)); while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar(); x*=h; } void write(long long x){ if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0; do{st[++tot]=x%10,x/=10;} while(x); while(tot){putchar(st[tot--]+'0');} } void write(long long x,char y){write(x);write(y);} #endif const int MAXN = 4e5+10; int n,s,a[MAXN],p,sum[MAXN]; signed main(){ read(n);read(s); for(int i = 1;i<=n;i++) read(a[i]),p+=a[i],sum[i] = sum[i-1]+a[i]; for(int i = n+1;i<=2*n;i++) a[i] = a[i-n],sum[i] = sum[i-1]+a[i]; s%=p; if(s==0) return puts("Yes"); int l = 1,r = 1; while(l<=2*n){ while(sum[r]-sum[l-1]<s&&r<=2*n) r++; if(sum[r]-sum[l-1]==s) return puts("Yes"); l++; } puts("No"); return 0; } } signed main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); // ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int T = 1; // gtx::read(T); while(T--) gtx::main(); return 0; }
本文作者:gutongxing
本文链接:https://www.cnblogs.com/gutongxing/p/18607252
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步