AtCoder Beginner Contest竞赛题解 | AtCoder Beginner Contest 428

📅 发布时间:2026/7/3 1:37:42 👁️ 浏览次数:
AtCoder Beginner Contest竞赛题解 | AtCoder Beginner Contest 428
​欢迎大家订阅我的专栏算法题解C与Python实现本专栏旨在帮助大家从基础到进阶 逐步提升编程能力助力信息学竞赛备战专栏特色1.经典算法练习根据信息学竞赛大纲精心挑选经典算法题目提供清晰的代码实现与详细指导帮助您夯实算法基础。2.系统化学习路径按照算法类别和难度分级从基础到进阶循序渐进帮助您全面提升编程能力与算法思维。适合人群准备参加蓝桥杯、GESP、CSP-J、CSP-S等信息学竞赛的学生希望系统学习C/Python编程的初学者想要提升算法与编程能力的编程爱好者附上汇总帖AtCoder Beginner Contest竞赛题解 | 汇总A - Grandma’s Footsteps【题目来源】洛谷[AT_abc428_a ABC428A] Grandma’s Footsteps - 洛谷【题目描述】Takahashi is enjoying a game at school. The game starts at the moment the bell rings.高桥正在学校玩一个游戏。游戏在上课铃响时开始。Immediately after the bell rings, he repeats the following actions:铃响后他立即重复以下动作Run at a speed ofS SSmeters per second forA AAseconds. Then, remain stationary forB BBseconds.以每秒S SS米的速度奔跑A AA秒然后静止B BB秒。How many meters in total does he run by the timeX XXseconds have elapsed since the bell rang?从铃响开始经过X XX秒后他总共跑了多少米【输入】The input is given from Standard Input in the following format:S A B X【输出】Output the answer in one line. Omit the unit (meters) in the output.【输入样例】7 3 2 11【输出样例】49【算法标签】《洛谷 AT_abc428_a Grandma’s Footsteps》 #模拟#【代码详解】#includebits/stdc.husingnamespacestd;ints;// 每个时间单位产生的物品数量inta;// 机器A的工作时间intb;// 机器B的休息时间intx;// 总时间intans;// 总产量intmain(){// 输入参数cinsabx;// 计算完整的工作周期数inttx/(ab);// 计算完整周期内的产量每个周期生产s*a个物品anss*a*t;// 计算剩余时间的产量intt2x%(ab);// 如果剩余时间大于等于机器A的工作时间if(t2a){// 剩余时间内机器A可以完整工作anss*a;}else{// 剩余时间内机器A只能部分工作anst2*s;}// 输出总产量coutansendl;return0;}【运行结果】7 3 2 11 49B - Most Frequent Substrings【题目来源】洛谷[AT_abc428_b ABC428B] Most Frequent Substrings - 洛谷【题目描述】You are given a stringS SSof lengthN NNconsisting of lowercase English letters.给定一个长度为N NN、由小写英文字母组成的字符串S SS。Define thenumber of occurrencesof a stringt ttof lengthK KKas the number of integersi iithat satisfy the following condition:将长度为K KK的字符串t tt的出现次数定义为满足以下条件的整数i ii的数量1 ≤ i ≤ N − K 1 1 \leq i \leq N-K11≤i≤N−K1The substring ofS SSfrom thei ii-th character to the( i K − 1 ) (iK-1)(iK−1)-th character matchest tt.S SS中从第i ii个字符到第( i K − 1 ) (iK−1)(iK−1)个字符的子串与t tt匹配。Find the maximum valuex xxof the number of occurrences of a string of lengthK KK. Also, output all strings of lengthK KKwithx xxoccurrences in ascending lexicographical order.求长度为K KK的字符串出现次数的最大值x xx。同时按字典序升序输出所有出现次数为x xx的长度为K KK的字符串。【输入】The input is given from Standard Input in the following format:N K S【输出】Output two lines.The first line should contain the maximum valuex xxof the number of occurrences of a string of lengthK KK.The second line should contain all strings of lengthK KKwithx xxoccurrences in ascending lexicographical order, separated by spaces.【输入样例】9 3 ovowowovo【输出样例】2 ovo owo【算法标签】《洛谷 AT_abc428_b Most Frequent Substrings》 #模拟# #排序#【代码详解】#includebits/stdc.husingnamespacestd;intn;// 字符串总长度intk;// 子串长度intmaxn-1e9;// 最大出现次数初始化为极小值string s;// 输入字符串string ans[105];// 存储出现次数最多的子串intcur0;// 记录结果子串的数量mapstring,intmp;// 用于统计子串出现次数的映射表intmain(){// 输入字符串长度、子串长度和字符串cinnk;cins;// 在字符串前添加空格使索引从1开始s s;// 提取所有长度为k的子串并统计出现次数for(inti1;in-k1;i){string ts.substr(i,k);// 提取从位置i开始长度为k的子串mp[t];// 增加该子串的计数}// 找出子串的最大出现次数for(autox:mp){maxnmax(maxn,x.second);// 更新最大出现次数}// 输出最大出现次数coutmaxnendl;// 收集所有出现次数等于最大值的子串for(autox:mp){if(x.secondmaxn){ans[cur]x.first;// 保存符合条件的子串}}// 对结果子串按字典序排序sort(ans1,anscur1);// 输出所有出现次数最多的子串for(inti1;icur;i){coutans[i] ;}coutendl;return0;}【运行结果】9 3 ovowowovo 2 ovo owo