uva 7219 Problem on Group Trip (优先队列)
来源:互联网 发布:ppt mac版如何加页码 编辑:程序博客网 时间:2024/05/19 17:56
题意:
三种洗漱房s1,s2,s3,n个人,每个人按1到3的顺序排队等候洗漱,给出每人在这三个洗漱房需要多少时间洗漱,并且排队过程中,编号小的先洗漱,问需要多少时间所有人完成洗漱
解题思路:
用优先队列存储在3个房间的等候队列,如果洗漱完了,就加入到下一个队列,注意如果两个相邻队列队首的人同时完成洗漱,比如s1,s2房间两人同时,完成,就先让s1那人先进入s2房间排队,然后再s2队列中编号最小的人去洗漱. 代码写的有乱,写了一个多小时,最后差一秒,交上ac,qaq.
代码:
#include <bits/stdc++.h>using namespace std;const int maxn=105;struct p { int tim[4]; int x; bool operator <(const p &a)const { return a.x<x; } }now[4], b[maxn];int main(){ int t; cin>>t; int e=1; while(t--) {int n;scanf("%d", &n);priority_queue<p>a[4]; int i, j;for(i=0; i<3; i++){ now[i].tim[0]=now[i].tim[1]=now[i].tim[2]=0;}for(i=0; i<n; i++){ scanf("%d %d %d", &b[i].tim[0], &b[i].tim[1], &b[i].tim[2]); b[i].x=i; if(b[i].tim[0]!=0) { a[0].push(b[i]); } else if(b[i].tim[1]!=0) { a[1].push(b[i]); } else if(b[i].tim[2]!=0)a[2].push(b[i]);}int book[5];memset(book, 0, sizeof(book));int ans=0;for(i=0; i<3; i++){ if(!a[i].empty()) { now[i]=a[i].top(); // printf("%d ", now[i].x); a[i].pop(); }}printf("Case #%d: ", e++); while(now[0].tim[0]!=0||now[1].tim[1]!=0|| now[2].tim[2]!=0){ int mi=104, x=0;for(i=0; i<3; i++){ if(now[i].tim[i]!=0) { if(now[i].tim[i]<mi) {mi=now[i].tim[i];x=i; } }}ans+=mi;if(mi==0)break;//printf("now");memset(book, 0, sizeof(book));for(i=0; i<3; i++){ if(now[i].tim[i]>0)now[i].tim[i]-=mi, book[i]=1; // printf("%d ", now[i].tim[i]); if(now[i].tim[i]==0 && book[i]==1) if(i<2) {if(now[i].tim[i+1]!=0) a[i+1].push(now[i]);else if(i==0 && now[i].tim[i+2]!=0)a[i+2].push(now[i]); }}for(i=0; i<3; i++){ if(now[i].tim[i]==0) { if(!a[i].empty()) { now[i]=a[i].top(); a[i].pop(); } }}//printf("\n");}printf("%d\n", ans); }}
0 0
- uva 7219 Problem on Group Trip (优先队列)
- Problem on Group Trip UVALive - 7219 (模拟+优先队列处理)
- Problem on Group Trip UVALive - 7219
- Problem on Group Trip----暴力水题
- uva 10047 Problem A: The Monocycle (搜索:BFS+优先队列)
- HDU2425:Hiking Trip(BFS+优先队列)
- HDU 2425-Hiking Trip(BFS+优先队列)
- HDU 2425 Hiking Trip(BFS+优先队列)
- Hiking Trip(bfs+优先队列)
- HDU2425:Hiking Trip(BFS+优先队列)
- HDU2425 Hiking Trip(bfs+优先队列)
- UVa Problem Solution: 10137 - The Trip
- UVa Problem 10137 The Trip (旅行)
- UVa Problem 10137 The Trip (旅行)
- UVA - 11997(优先队列)
- HDU 2425 Hiking Trip(搜索+优先队列)
- HDU 2425 Hiking Trip(bfs+优先队列)
- HDU 2425 Hiking Trip(bfs+优先队列)
- greenplum探索学习
- ceph - 更改 ceph journal 位置
- 说说ListView,Percent布局以及RecyclerView
- JAVA通过XPath解析XML性能比较
- 全栈必备的技术栈设想
- uva 7219 Problem on Group Trip (优先队列)
- Zigbee Smart Energy安全加密机制
- bash shell脚本访问PostgreSQL的三种方式
- Java信号量Semaphore整理
- MTCNN训练数据整理
- 状压-[SCOI2005]互不侵犯King
- shell调用python脚本,并且向python脚本传递参数
- hadoop-2.6.4集群编译搭建-阿里云和腾讯云
- memcached安装与基本使用