'commit'
This commit is contained in:
26
GESP/Level5/P1843_TanXin.cpp
Normal file
26
GESP/Level5/P1843_TanXin.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
// https://www.luogu.com.cn/problem/P1843
|
||||
priority_queue<int> q; // 每次很方便地找到最大值,默认是大顶堆
|
||||
int n, a, b;
|
||||
int ans;
|
||||
|
||||
int main() {
|
||||
cin >> n >> a >> b; // 衣服数目,自然晒干,烘干机晒干
|
||||
for (int i = 1; i <= n; i++) { // 第 i 件衣服的湿度为 w[i]
|
||||
int w;
|
||||
cin >> w;
|
||||
q.push(w);
|
||||
}
|
||||
int mx = q.top();
|
||||
q.pop(); // 每次考虑最湿的衣服就可以了
|
||||
while (mx > ans * a) { // 如果现在湿度最大的衣服,它在规定时间ans的情况下,自然就可以干了,那就是找到了第一个最小的ans答案
|
||||
ans++; // 增加1分钟,继续尝试看看是不是可以完成所有衣服的烘干
|
||||
mx -= b; // 我们默认的贪心策略是挑湿度高的先烘干,所以,烘干机肯定先给湿度最高的衣服使用
|
||||
q.push(mx);
|
||||
mx = q.top();
|
||||
q.pop(); // 重新更新,继续使用
|
||||
}
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user