​Cook Pancakes!​


from 2020ICPC济南
Time limit:1s
Memory limit:256MB

Cook Pancakes! | 2020ICPC济南M_icpc


Cook Pancakes! | 2020ICPC济南M_c++_02


先烤两面没烤的,再烤一面没烤的。

ac代码:
#include<bits/stdc++.h>
using namespace std;
int n,k,t; //如题n,k,t表示时间
priority_queue<int> q; //存储现有的饼
priority_queue<int> qq; //存储每一轮烤了过后的饼还有多少面未烤
int main(){
cin>>n>>k;
for(int i = 1;i <= n;++i)
q.push(2);
while(!q.empty()){
++t;
for(int i = 1;!q.empty() && i <= k;++i){
int a = q.top();
q.pop();
a -= 1;
if(a == 1)
qq.push(a);
}
while(!qq.empty())
q.push(qq.top()),qq.pop();
}
cout<<t;
return 0;
}