题解:AtCoder AT_awc0006_c Air Conditioner Temperature Adjustment
本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。欢迎大家订阅我的专栏算法题解C与Python实现附上汇总贴算法竞赛备考冲刺必刷题C | 汇总【题目来源】AtCoderC - Air Conditioner Temperature Adjustment【题目描述】Takahashi is the building manager of an office building. On a hot summer day, the air conditioner in each room has broken down, causing the room temperatures to rise too high.高桥是一栋办公楼的物业经理。在一个炎热的夏日每个房间的空调都发生故障导致室内温度过高。The building hasN NNrooms, and the current temperature of roomi ii( 1 ≤ i ≤ N ) (1 \leq i \leq N)(1≤i≤N)isT i T_iTidegrees. To ensure employees can work comfortably, the temperature of every room must be brought to at most the target temperature ofM MMdegrees.该楼有N NN个房间房间i ii1 ≤ i ≤ N 1 ≤ i ≤ N1≤i≤N的当前温度为T i T_iTi度。为确保员工能舒适工作必须将每个房间的温度降至最多为目标温度M MM度。Takahashi can use as many cooling packs as needed. Using1 11cooling pack lowers the temperature of one chosen room by exactlyD DDdegrees. A cooling pack cannot be used partially; each pack always lowers the temperature by exactlyD DDdegrees. Multiple cooling packs can be used on the same room, and it is acceptable if a room’s temperature drops well belowM MMdegrees or even becomes negative as a result.高桥可以根据需要使用任意数量的冷却包。使用1 11个冷却包可将选定房间的温度恰好降低D DD度。冷却包不能部分使用每个冷却包总是恰好降低温度D DD度。可以在同一房间使用多个冷却包并且允许房间温度因此远低于M MM度甚至变为负数。Find the minimum number of cooling packs needed to bring the temperature of every room toM MMdegrees or below.求将每个房间的温度降至M MM度或以下所需的最少冷却包数量。【输入】N NNM MMD DDT 1 T_1T1T 2 T_2T2… \ldots…T N T_NTNThe first line contains three space-separated integers:N NNrepresenting the number of rooms,M MMrepresenting the target temperature, andD DDrepresenting the temperature decrease per cooling pack.The second line contains space-separated integersT 1 , T 2 , … , T N T_1, T_2, \ldots, T_NT1,T2,…,TNrepresenting the current temperature of each room.【输出】Print a single integer on one line: the minimum number of cooling packs needed to bring the temperature of every room toM MMdegrees or below.【输入样例】3 25 5 30 28 20【输出样例】2【解题思路】【算法标签】#模拟#【代码详解】#includebits/stdc.husingnamespacestd;#defineintlonglongintn,m,d,ans;// n: 数据个数m: 阈值d: 除数ans: 结果signedmain(){cinnmd;// 读入数据个数、阈值和除数for(inti1;in;i){intt;cint;// 读入当前数据if(tm)// 如果当前数据小于等于阈值跳过{continue;}// 计算超过阈值部分需要多少个d// 公式ceil((t - m) / d) 的整数计算技巧// ((t - m) (d - 1)) / dans((t-m)(d-1))/d;}coutansendl;// 输出结果return0;}【运行结果】3 25 5 30 28 20 2