您的位置:首页 > 大数据 > 人工智能

PAT 甲 1014. Waiting in Line (30)(优先队列)

2017-10-25 23:17 465 查看

题目链接

1014. Waiting in Line (30)

分析

感觉这些题都好水的~~,直接优先队列模拟就好了

AC code

#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define mp make_pair
const int maxn = 1e3+10;
const int MAX_TIME = 9*60;
typedef pair<int,int > Pair;

int need[maxn];
int last[maxn];
int finish[maxn];
int main()
{

priority_queue< Pair,std::vector<Pair>, greater<Pair> > Q;
int N,M,K,q;
cin>>N>>M>>K>>q;
for(int i=0 ; i<K ; ++i){
scanf("%d",need+i );
}
memset(last,0,sizeof(last));
memset(finish,-1,sizeof(finish));
for(int i=0 ; i<M ; ++i){
for(int j=0 ; j<N ; ++j){
if(last[j]>=MAX_TIME)continue;
finish[i*N+j] = last[j] + need[i*N+j];
last[j] = finish[i*N+j];
Q.push(mp(finish[i*N+j],j));
}
}
for(int i = N*M ; i<K && !Q.empty(); ++i){
Pair p = Q.top(); Q.pop();
if(last[p.se]>=MAX_TIME)continue;
finish[i] = last[p.se]+need[i];
last[p.se] = finish[i];
Q.push(mp(finish[i],p.se));
}
while (q--) {
int x;
scanf("%d",&x );x--;
if(finish[x]==-1){printf("Sorry\n" );}
else{
int t = finish[x]/60+8,fen = finish[x] % 60;
printf("%02d:%02d\n",t,fen );
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息