news 2026/4/29 21:32:39

题解:AtCoder AT_awc0006_c Air Conditioner Temperature Adjustment

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
题解:AtCoder AT_awc0006_c Air Conditioner Temperature Adjustment

本文分享的必刷题目是从蓝桥云课洛谷AcWing等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。

欢迎大家订阅我的专栏:算法题解:C++与Python实现!

附上汇总贴:算法竞赛备考冲刺必刷题(C++) | 汇总


【题目来源】

AtCoder:C - 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)(1iN)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 ≤ N1iN)的当前温度为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 DD
T 1 T_1T1T 2 T_2T2… \ldotsT N T_NTN

  • The 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

【解题思路】

【算法标签】

#模拟#

【代码详解】

#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintn,m,d,ans;// n: 数据个数,m: 阈值,d: 除数,ans: 结果signedmain(){cin>>n>>m>>d;// 读入数据个数、阈值和除数for(inti=1;i<=n;i++){intt;cin>>t;// 读入当前数据if(t<=m)// 如果当前数据小于等于阈值,跳过{continue;}// 计算超过阈值部分需要多少个d// 公式:ceil((t - m) / d) 的整数计算技巧// ((t - m) + (d - 1)) / dans+=((t-m)+(d-1))/d;}cout<<ans<<endl;// 输出结果return0;}

【运行结果】

3 25 5 30 28 20 2
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/29 21:30:25

从MVP到MVVM:Android架构演进与最佳实践指南

从MVP到MVVM&#xff1a;Android架构演进与最佳实践指南 【免费下载链接】android-mvp-architecture This repository contains a detailed sample app that implements MVP architecture using Dagger2, GreenDao, RxJava2, FastAndroidNetworking and PlaceholderView 项目…

作者头像 李华
网站建设 2026/4/29 21:27:28

Axure RP 11中文界面终极改造:告别英文困扰的完整指南

Axure RP 11中文界面终极改造&#xff1a;告别英文困扰的完整指南 【免费下载链接】axure-cn Chinese language file for Axure RP. Axure RP 简体中文语言包。支持 Axure 11、10、9。不定期更新。 项目地址: https://gitcode.com/gh_mirrors/ax/axure-cn 还在为Axure R…

作者头像 李华
网站建设 2026/4/29 21:22:28

终极指南:AnyLabeling本地部署全攻略,保护敏感数据安全无忧

终极指南&#xff1a;AnyLabeling本地部署全攻略&#xff0c;保护敏感数据安全无忧 【免费下载链接】anylabeling Effortless AI-assisted data labeling with AI support from YOLO, Segment Anything (SAMSAM2/2.1SAM3), MobileSAM!! 项目地址: https://gitcode.com/gh_mir…

作者头像 李华