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,求到达终点的最少耗时. 解题思路: ...
随机推荐
- Chapter 1 First Sight——30
The girl sitting there giggled. I'd noticed that his eyes were black — coal black. 那个坐在那里的女孩笑着.我注意到她 ...
- H5的新应用-拖到页面上的元素
-------------------------- <script type="text/javascript"> // ...
- redis第一篇--综述
1 redis里边有数据库的概念.可分为1-255这些表.在存储或者查找的时候要指明. redis_sentinel 集群里边封装成了namespace这样的概念.与db是不一样的.
- c语言中->的一个作用
为了使用方便和直观,c语言中结构体指针带成员(*p).num可以用p->num来代替. ->称为指向运算符:
- Ubuntu DNS bind9 配置
下面的配置就是实现解析test.zp.com到不同的IP地址 安装dns server软件包$ apt-get install bind9 配置dns配置文件的路径在/etc/bind路径下面添加一个 ...
- 关于PHP静态方法调用和实例化类调用的区别
1.首先来澄清一些观点 由于静态方法在内存中只有一份,无论你调用多少次,都是共用的,而且没有对象的概念,所以不能在静态方法里面使用$this调用,如果非得调用的话,只能实例化自身类 而实例化不一样,每 ...
- centos配置samba
一.samba服务器的安装与配置 [root@localhost ~]# yum -y install samba samba-common samba-client samba服务器所 ...
- UIView的基本属性及ANimation
frame属性:可以使用该属性改变尺寸和位置 相对于父视图bounds:改变尺寸 相对自身center:改变视图的位置alpha:改变视图的透明度backgroundColor:改变视图的背景cont ...
- WordPress 邮箱防抓取
现在网络上有很多爬虫,专门四处搜集网站代码中出现的邮箱,搜集到了之后就批量出售或者发送垃圾邮件.很多人都把邮箱中的 “@” 换成 “#”,但这样对用户不太方便,而且这种方法很多机器人都可以识破,同样被 ...
- ABI & API
API defines the programning language and function entry point, arguments type, order. ABI defines th ...