题目:1014 Waiting in Line (30 分)
题解:注意事项!!!血的教训
1.首先就是只要在17:00之前接受服务的客户,及时截止时间超过17:00,也是会被服务的,也就是说不能输出sorry
2.注意n、m的取值,如果两个等于0 ???所以这里对队列的处理最好是i<=n*m。这个错误找了好久,看我下面那个注释掉的,就是窗口前的第1位和后面m-1位拆开来处理了,会导致错误的发生
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int ,int> PII;
const int N=1010;
const int mod=100000007;
const int MAXX=0x3f3f3f3f;
int n,m,K,Q;
typedef struct Node{
int id;
int time;
}node;
typedef struct Que{
int w_id;
int ed;
node no;
bool operator<(const struct Que & a)const{
if(ed!=a.ed)return ed>a.ed;
return w_id>a.w_id;
}
}que;
node nd[N];
int query[N];
int records[N];
int main(){
cin>>n>>m>>K>>Q;
priority_queue<que> q;
queue<node> qu[25];
int k=1;
for(int i=1;i<=K;i++){
cin>>nd[i].time;
nd[i].id=i;
}
for(int i=1;i<=Q;i++){
cin>>query[i];
}
//预处理队列
/*
for(int i=1;i<=n;i++){
que t;
t.w_id=i;
if(k<=K){
t.ed=nd[k].time;
t.no=nd[k];
k++;
}else t.ed=MAXX;
q.push(t);
}
for(int i=1;i<=n;i++){
for(int j=1;j<m;j++){
if(k<=K){
qu[i].push(nd[k++]);
}
}
}
*/
for(int i=1;i<=n*m;i++){
if(i<=n){
que t;
t.w_id=i;
if(k<=K){
t.ed=nd[k].time;
t.no=nd[k];
k++;
}else t.ed=MAXX;
q.push(t);
}else{
if(k<=K){
if(i%n==0)
qu[n].push(nd[k++]);
else
qu[i%n].push(nd[k++]);
}
}
}
//cout<<"1:"<<endl;
memset(records,-1,sizeof records);
int Time=0;
while(1){
que t=q.top();
if(t.ed==0x3f3f3f3f) break;
if(Time<t.ed) {
Time=t.ed;
continue;
}
q.pop();
records[t.no.id]=t.ed;
if(qu[t.w_id].size()){
que tmp;
tmp.ed=t.ed+qu[t.w_id].front().time;
tmp.w_id=t.w_id;
tmp.no=qu[t.w_id].front();
qu[t.w_id].pop();
q.push(tmp);
if(k<=K){
qu[t.w_id].push(nd[k++]);
}
}else{
if(m==1){
if(k<=K){
que tmp;
tmp.ed=t.ed+nd[k].time;
tmp.w_id=t.w_id;
tmp.no=nd[k];
q.push(tmp);
k++;
}
}else{
que tmp;
tmp.ed=MAXX;
tmp.w_id=t.w_id;
q.push(tmp);
}
}
}
//for(int i=1;i<=K;i++)
// cout<<records[i]<<" ";
//cout<<endl;
for(int i=1;i<=Q;i++){
if(records[query[i]]==-1||records[query[i]]-nd[query[i]].time>=9*60){
cout<<"Sorry";
}else{
printf("%02d:%02d",8+records[query[i]]/60,records[query[i]]%60);
}
if(i!=Q) cout<<endl;
}
return 0;
}