注解
1、模拟
2、队列
3、字符串转整型。
4、用数组简化代码。
5、注意排队和不排队两种情况的区分。不排队有两种情况:(1)桌子本身就每坐满。(2)桌子虽然坐满了(逻辑上的坐满,也就是size等于最大size),但最近一个离开的客人的离开时间比当前客人进来的时间要早。而排队只有一种情况:桌子坐满了,并且最近一个离开的客人比当前进来的时间晚,且不超过半小时。
代码
#include <iostream>
#include <queue>
#include <sstream>
#include <cmath>
using namespace std;
const int maxn = 4;
int strToInt(string s) {
int t = 0;
stringstream ss;
ss<<s;
ss>>t;
return t;
}
int main() {
int A[maxn];
cin>>A[1]>>A[2]>>A[3];
while(A[1] || A[2] || A[3]) {
int ans = 0;
queue<int> q[maxn];
string tim;
cin>>tim;
while(tim.compare("#")) {
int now = 60 * strToInt(tim.substr(0, 2)) + strToInt(tim.substr(3, 2));
int num;
cin>>num;
int index = ceil(num/2.0);
if(q[index].size()<A[index]) {
ans += num;
q[index].push(now+30);
} else {
int top = q[index].front();
if(now>=top){
q[index].pop();
q[index].push(now+30);
ans+=num;
}
else if(now+30>=top) {
q[index].pop();
q[index].push(top+30);
ans+=num;
}
}
cin>>tim;
}
cout<<ans<<endl;
cin>>A[1]>>A[2]>>A[3];
}
return 0;
}