HDU 4393 Throw nails(优先队列)
优先队列的应用
好坑,好坑,好坑,重要的事情说三遍!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 50005
struct Node
{
int f,s,id;
friend bool operator < (Node a,Node b)
{
if(a.f != b.f) return a.f < b.f;
else return a.id > b.id;
}
} node[maxn];
priority_queue<Node>que[];
int main()
{
int t,n,Case =;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i =; i < n; i++)
{
scanf("%d%d",&node[i].f,&node[i].s);
node[i].id = i+;
que[node[i].s].push(node[i]);
}
printf("Case #%d:\n",++Case);
int now =;
while(n--)
{
int maxt = -,minid =,pos =;
for(int i =; i <=; i++)
{
if(!que[i].empty())
{
Node te = que[i].top();
int tmp = te.f + te.s*now;
if(tmp > maxt)
{
maxt = tmp;
minid = te.id;
pos = i;
}
if(tmp == maxt)
{
if(te.id < minid)
{
minid = te.id;
pos = i;
}
}
}
}
if(!que[pos].empty())que[pos].pop();
if(n ==) printf("%d",minid);
else printf("%d ",minid);
now++;
}
puts("");
}
}
HDU 4393 Throw nails(优先队列)的更多相关文章
- HDU 4393 Throw nails
Throw nails Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 4393 Throw nails(STL之优先队列)
Problem Description The annual school bicycle contest started. ZL is a student in this school. He is ...
- HDU 4393 Throw nails(贪心加模拟,追及问题)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115361#problem/D 题意大致是:给出最多50000个人,拥有最初速度 ...
- 【HDOJ】4393 Throw nails
水题,优先级队列. /* 4393 */ #include <iostream> #include <sstream> #include <string> #inc ...
- hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)
...
- HDU 4857 拓扑排序 优先队列
n个数,已经有大小关系,现给m个约束,规定a在b之前,剩下的数要尽可能往前移.输出序列 大小关系显然使用拓扑结构,关键在于n个数本身就有大小关系,那么考虑反向建图,优先选择值最大的入度为零的点,这样得 ...
- hdu 4393 优先队列
用优先队列储存每个人的初始距离和编号,每轮求出最快的人,然后pop掉 一开始想遍历队列的,后来发现队列没办法遍历,汗-_-! 题意,给几个第一秒冲出的距离和以后速度,求每秒后最前面人的编号,求完后最前 ...
- 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,求到达终点的最少耗时. 解题思路: ...
随机推荐
- 关于C++数组的几点讨论
数组名为何物? int main() { , , , , }; int *pnumber = number; cout << sizeof(number) << endl; c ...
- OpenCV——mixChannels函数
mixChannels Copies specified channels from input arrays to the specified channels of output arrays. ...
- ECSTORE1.2系统更改后台密码
<?php set_time_limit(0); error_reporting(E_ALL^E_NOTICE); ?> <META HTTP-EQUIV="content ...
- [转]phpcms 判断用户登录代码
<!-- 用户登录开始 --> <?php //读取用户信息 $ypzy_userid = param::get_cookie('_userid'); if(!empty($ypzy ...
- Django Template模板
Django Template 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python 代码之中. 下面我们来调用html views def ind ...
- asp:Property解释与例子
=======================================================================Property Get 语句在 Class 块中,声明构 ...
- sql语句操作表
"create table mytable (m_id integer identity(1,1) primary key,m_class varchar(50) not null defa ...
- Java学习笔记之类和对象
1.类是对象的抽象,对象是类的实例. 2.一个.java 文件,只能有一个公有类. 3.Java的默认访问权限是:default,即不加任何访问修饰符,该权限设置只能在同一包访问. 当前类 同一包 ...
- 【欧拉函数】 poj 2478
递推法求欧拉函数: #include <iostream> #include <cstdio> #include <cstring> using namespace ...
- 一款值得推荐的shell工具
1. 一款比较出色的shell工具 熟练的运用shell语言可以提高我们的工作效率,而一款好的shell工具能提高学习的效率,fish shell就是这样一款工具.并且是一款跨平台的工具, 同时可以在 ...