HDU 1434 幸福列车(优先队列)
优先队列的应用
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 10010
struct Node
{
string name;
int rp;
friend bool operator <(Node a,Node b)
{
if(a.rp != b.rp) return a.rp > b.rp;
else return a.name < b.name;
}
};
priority_queue<Node>que[maxn];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
Node tmp;
for(int i =;i <= n;i++)
{
int k;
scanf("%d",&k);
while(!que[i].empty()) que[i].pop();
while(k--)
{
cin>>tmp.name>>tmp.rp;
que[i].push(tmp);
}
}
while(m--)
{
char op[];
scanf("%s",op);
if(!strcmp(op,"GETON"))
{
int id;
scanf("%d",&id);
cin>>tmp.name>>tmp.rp;
que[id].push(tmp);
}
else if(!strcmp(op,"JOIN"))
{
int i1,i2;
scanf("%d%d",&i1,&i2);
while(!que[i2].empty())
{
tmp = que[i2].top();
que[i2].pop();
que[i1].push(tmp);
}
}
else
{
int id;
scanf("%d",&id);
tmp = que[id].top();
que[id].pop();
cout<<tmp.name<<endl;
}
}
}
return;
}
HDU 1434 幸福列车(优先队列)的更多相关文章
- hdu 1434 幸福列车
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1434 幸福列车 Description 一批幸福的列车即将从杭州驶向幸福的终点站——温州,身为总列车长 ...
- hdu 1434 幸福列车 (Leftist Tree)
Problem - 1434 网上题解是普通的堆合并,都是用优先队列直接做的.可是正解的堆合并应该是用左偏堆或者斐波那契堆的吧,不然O(X * N ^ 2)的复杂度应该是过不了的.斐波那契堆的实现相对 ...
- HDU 4857 拓扑排序 优先队列
n个数,已经有大小关系,现给m个约束,规定a在b之前,剩下的数要尽可能往前移.输出序列 大小关系显然使用拓扑结构,关键在于n个数本身就有大小关系,那么考虑反向建图,优先选择值最大的入度为零的点,这样得 ...
- HDU 4857 逃生 (优先队列+反向拓扑)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 解题报告:有n个点,有m个条件限制,限制是像这样的,输入a b,表示a必须排在b的前面,如果不 ...
- HDU 1242 (BFS搜索+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目大意:多个起点到一个终点,普通点耗时1,特殊点耗时2,求到达终点的最少耗时. 解题思路: ...
- HDU 5638 拓扑排序+优先队列
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5638 题意: 给你一个DAG图,删除k条边,使得能个得到字典序尽可能小的拓扑排序 题解: 把拓扑排序 ...
- hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了 ...
- HDU 1242 Rescue(优先队列)
题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by ...
- HDU 1242 Rescue(BFS+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by t ...
随机推荐
- The List ADT
1.Definiation A list is a sequence. a0, a1,a2,..., aN (N>0) 2.Character For any list except the ...
- LeetCode OJ 99. Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- 关于getchar()的知识
char* s1 = "123",字符串"123"这段内存是只读的,就是说其内容不能改变///char *s 这个是指申请一个地址空间 记录一个地址 #incl ...
- Centos7下安装numpy+matplotlib+scipy
摘自:http://litchiware.github.io/centos/2015/07/05/centos7%E4%B8%8B%E5%AE%89%E8%A3%85numpy+matplotlib+ ...
- oracle即时客户端安装方法
http://blog.csdn.net/magicboylinw/article/details/7025885 Oracle Instant Client(即时客户端) 安装与配置 oracleO ...
- login/logout切换
1. 前端按钮 <img border="0" width="18" height="18" src="<%=base ...
- QT插件和服务培训
下载地址:http://files.cnblogs.com/files/senior-engineer/%E6%8F%92%E4%BB%B6%E5%92%8C%E6%9C%8D%E5%8A%A1%E5 ...
- python http请求
from httplib2 import Http def postDada(): http=Http() heads={"pragma":"no-cache" ...
- List<T> 求差集
List<, , , , , }; List<, , , , , }; List<int> c = b.Except(a).ToList(); foreach (int i i ...
- 最简单的入门github
下载 git clone ***(地址) 上传 1. 先注册一个github账号 2.在github网站上建设一个工程 3. 把想要上传的数据上传到网站去 1 git config --glob ...