当前位置: 首页 > news >正文

代码源挑战赛 Round 41

代码源挑战赛 Round 41

2025.12.12

A. [R41A]出题组3

link
image
image

\(Solution:\)

用取模模拟即可。

code
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define inf 1e12
#define eps 1e-9
#define endl "\n"
#define il inline
#define ls 2*k
#define rs 2*k+1
using namespace std;
const int N=2e5+5,M=3e6+5;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;
}
int n,x,y,k; 
signed main(){n=read(),x=read(),y=read(),k=read();for(int i=x+1;i<=k;i++) y=(y+1)%n;cout<<(!y ? n : y);return 0;
}

B. [R41B]购物

link
image
image

\(Solution:\)

贪心。将 \(a_i\) 升序排序,先选较小的 $ a_i $ 。

code
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define inf 1e12
#define eps 1e-9
#define endl "\n"
#define il inline
#define ls 2*k
#define rs 2*k+1
using namespace std;
const int N=2e5+5,M=3e6+5;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;
}
int n,a[N],V,ans;
signed main(){n=read(),V=read();for(int i=1;i<=n;i++) a[i]=read();sort(a+1,a+n+1);for(int i=1;i<=n;i++){V-=a[i];if(V>=0) ans=max(ans,i);else break;}cout<<ans;return 0;
}

C. [R41C]文本编辑器

link
image
image

\(Solution:\)

维护一个栈来模拟打字过程即可。

code
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define inf 1e12
#define eps 1e-9
#define endl "\n"
#define il inline
#define ls 2*k
#define rs 2*k+1
using namespace std;
const int N=5e5+5,M=3e6+5;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;
}
int n,flag=1,top;
char res[N],s[N];
signed main(){ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);cin>>n;for(int i=1;i<=n;i++) cin>>s[i];for(int i=1;i<=n;i++){if(s[i]>='a' && s[i]<='z'){if(flag==1) res[++top]=s[i];else res[++top]=(s[i]-32);}else if(s[i]=='@') flag^=1;else{if(top) top--;}}for(int i=1;i<=top;i++) cout<<res[i];return 0;
}
http://www.rkmt.cn/news/89247.html

相关文章:

  • 详细介绍:NumPy / pandas 类型选型、内存占用与性能优化
  • 告别选择困难!2025年远程控制软件场景化终极横评
  • 青少年编程学习:考级与竞赛如何平衡
  • 2025 Autel MaxiVCI V150 Wireless Dongle: CAN FD/DOIP for Autel 900 Series Scanners
  • 【题解】Luogu P8269 [USACO22OPEN] Visits S
  • Ubuntu环境中LLaMA Factory 的部署与配置—构建大语言模型微调平台 - 实践
  • WSL安装方法
  • 【题解】P11453 [USACO24DEC] Deforestation S
  • 【dl】【WSL2】如何获得“Winux”?Windows 上的 Linux 子系统 —— 比虚拟机更好的选择
  • CSS3动画:2D/3D转换全解析
  • P2014 [CTSC1997] 选课
  • 彻底讲清 MySQL InnoDB 锁机制:从 Record 到 Next-Key 的全景理解
  • MCU的启动流程你了解么?
  • I2C通信最全面的讲解:从协议到硬件设计
  • 【题解】Luogu P10752 [COI 2024] Sirologija
  • Python字符串:别只用来打印!这5个高级用法让代码效率翻倍
  • 【题解】Atcoder ABC432 C
  • 赶due党救急!论文降重2小时搞定,不熬夜
  • 计算机论文模板推荐:8大平台+AI修改工具
  • 期待回家,顺便写点年度总结
  • E No address added out of total 1 resolved地址绑定失败: No address added out of total 1 resolved errors:
  • JavaScript 异常原因(Error Cause):实现分布式系统错误链追踪的序列化与反序列化
  • JavaScript 记录(Records)与 元组(Tuples):实现堆内存中不可变复合数据结构的内存布局
  • 线程并发编程,同步与互斥机制
  • Python列表与元组:搞懂这3个核心差异,再也不纠结用哪个
  • MQ消息队列相关知识与对比
  • 完整教程:PPT导出为图片的格式选择:JPG与PNG的区别
  • 代码随想录算法训练营第三十二天 | 完全背包、518. 零钱兑换 II、377. 组合总和 Ⅳ、卡码网57. 爬楼梯
  • 基于深度学习的文物图像修复系统
  • JavaScript 引擎中的分支预测器(Branch Predictor)友好性:如何写出减少 CPU 误判的代码