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; }
相关文章推荐
- PAT 1014. Waiting in Line (30)
- PAT 1014. Waiting in Line (30)
- [ZJU.PAT] 1014. Waiting in Line (30)
- PAT(A) - 1014. Waiting in Line (30)
- PAT 1014. Waiting in Line (30)
- PAT 甲级 1014. Waiting in Line (30)
- 1014. Waiting in Line (30)-PAT甲级真题(queue的应用)
- PAT (Advanced Level) Practise 1014. Waiting in Line (30)
- PAT 1014. Waiting in Line (30) 队列模拟 +简单消费者生产者
- PAT (Advanced) 1014. Waiting in Line (30)
- PAT 1014. Waiting in Line (30)(模拟排队等候)(待修改)
- 【PAT甲级】1014. Waiting in Line (30)
- 1014. Waiting in Line (30)-PAT
- pat 1014. Waiting in Line (30)
- PAT 1014. Waiting in Line (30)
- 1014. Waiting in Line (30)——PAT (Advanced Level) Practise
- 【PAT Advanced Level】1014. Waiting in Line (30)
- PAT (Advanced Level) 1014. Waiting in Line (30) 银行排队
- 1014. Waiting in Line (30)——PAT (Advanced Level) Practise
- PAT - 甲级 - 1014. Waiting in Line (30)(STL-queue)