题解:AtCoder AT_awc0005_b Updating the Report Card
本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。欢迎大家订阅我的专栏算法题解C与Python实现附上汇总贴算法竞赛备考冲刺必刷题C | 汇总【题目来源】AtCoderB - Updating the Report Card【题目描述】Takahashi is managing student grades as the homeroom teacher of a school class. There areN NNstudents in the class, numbered from1 11toN NN. The initial score of thei ii-th student isS i S_iSipoints.高桥担任学校班级的班主任负责管理学生成绩。班级中共有N NN名学生编号从1 11到N NN。第i ii名学生的初始分数为S i S_iSi分。At the end of the term, it is time to update the report cards. A total ofM MMupdates are performed. In thej jj-th update, the score of studentP j P_jPjis changed toV j V_jVjpoints. The same student may be updated multiple times, in which case their score is overwritten with each update.学期末到了更新成绩单的时候。总共执行M MM次更新。在第j jj次更新中学生P j P_jPj的分数被改为V j V_jVj分。同一名学生可能被多次更新这种情况下每次更新都会覆盖其之前的分数。After all updates are completed, students with a score strictly less thanK KKpoints are required to attend supplementary lessons. For Takahashi’s sake, determine the number of students who are required to attend supplementary lessons. Note that students with exactlyK KKpoints are not included.所有更新完成后分数严格小于K KK分的学生需要参加补习课程。为帮助高桥请确定需要参加补习课程的学生人数。注意分数恰好为K KK分的学生不包含在内。【输入】N NNM MMK KKS 1 S_1S1S 2 S_2S2⋯ \cdots⋯S N S_NSNP 1 P_1P1V 1 V_1V1P 2 P_2P2V 2 V_2V2⋮ \vdots⋮P M P_MPMV M V_MVMThe first line containsN NNrepresenting the number of students,M MMrepresenting the number of updates, andK KKrepresenting the threshold score for supplementary lessons, separated by spaces.The second line contains the initial scoresS 1 , S 2 , … , S N S_1, S_2, \ldots, S_NS1,S2,…,SNof each student, separated by spaces.S i S_iSirepresents the initial score of thei ii-th student.Lines3 33through2 M 2 M2Mcontain the details of the updates (ifM 0 M 0M0, this part does not exist).Line2 j 2 j2jcontains the student numberP j P_jPjwhose score is changed in thej jj-th update and the new scoreV j V_jVj, separated by a space.【输出】After all updates are completed, output in a single line the number of students whose score is strictly less thanK KKpoints and are therefore required to attend supplementary lessons.【输入样例】5 3 60 45 72 58 81 39 1 65 3 62 5 55【输出样例】1【解题思路】【算法标签】#模拟#【代码详解】#includebits/stdc.husingnamespacestd;constintN100005;intn,m,k,ans;// n: 学生数量m: 操作次数k: 分数线ans: 不达标人数ints[N];// 学生分数数组intmain(){cinnmk;// 读入学生数量、操作次数、分数线for(inti1;in;i){cins[i];// 读入学生初始分数}for(inti1;im;i){intp,v;// p: 学生编号v: 新分数cinpv;// 读入修改操作s[p]v;// 更新学生分数}for(inti1;in;i){if(s[i]k)// 如果学生分数低于分数线{ans;// 计数加1}}coutansendl;// 输出不达标人数return0;}【运行结果】5 3 60 45 72 58 81 39 1 65 3 62 5 55 1