hdu 4393 Throw nails(STL之优先队列)
The annual school bicycle contest started. ZL is a student in this school. He is so boring because he can't ride a bike!! So he decided to interfere with the contest. He has got the players' information by previous contest video. A player can run F meters the first second, and then can run S meters every second.
Each player has a single straight runway. And ZL will throw a nail every second end to the farthest player's runway. After the "BOOM", this player will be eliminated. If more then one players are NO.1, he always choose the player who has the smallest ID.
In the first line there is an integer T (T <= ), indicates the number of test cases.
In each case, the first line contains one integer n ( <= n <= ), which is the number of the players.
Then n lines follow, each contains two integers Fi( <= Fi <= ), Si ( < Si <= ) of the ith player. Fi is the way can be run in first second and Si is the speed after one second .i is the player's ID start from 1.
Huge input, scanf is recommended.
Huge output, printf is recommended.
For each case, the output in the first line is "Case #c:".
c is the case number start from .
The second line output n number, separated by a space. The ith number is the player's ID who will be eliminated in ith second end.
Case #:
Case #:
Hint
The first case:
1st Second end
Player1 100m (BOOM!!)
Player2 100m
Player3 3m
2nd Second end
Player2 102m
Player3 103m (BOOM!!)
3rd Second end
Player2 104m (BOOM!!)
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 50006
#define inf 1e12
int n;
struct Node{
int f,index;
friend bool operator < (Node a,Node b){
if(a.f!=b.f) return a.f<b.f;
return a.index>b.index;
}
};
int main()
{
int t;
int ac=;
scanf("%d",&t);
while(t--){ priority_queue<Node>q[]; scanf("%d",&n);
Node tmp;
int s;
for(int i=;i<=n;i++){
scanf("%d%d",&tmp.f,&s);
tmp.index=i;
q[s].push(tmp);
}
printf("Case #%d:\n",++ac);
for(int i=;i<n;i++){
int fast=-,id=;
for(int j=;j<=;j++){
if(!q[j].empty()){
Node cnt=q[j].top();
int now_dit=cnt.f+i*j;
if(now_dit>fast) fast=now_dit,id=j;
else if(now_dit==fast){
if(q[id].top().index>cnt.index){
id=j;
}
}
}
}
printf("%d",q[id].top().index);
q[id].pop();
if(i!=n-){
printf(" ");
}
}
printf("\n"); }
return ;
}
hdu 4393 Throw nails(STL之优先队列)的更多相关文章
- 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(优先队列)
优先队列的应用 好坑,好坑,好坑,重要的事情说三遍! #include<iostream> #include<cstdio> #include<cstring> # ...
- 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 ...
- STL之优先队列
STL 中优先队列的使用方法(priority_queu) 基本操作: empty() 如果队列为空返回真 pop() 删除对顶元素 push() 加入一个元素 size() 返回优先队列中拥有的元素 ...
- hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)
...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- hdu 4393 优先队列
用优先队列储存每个人的初始距离和编号,每轮求出最快的人,然后pop掉 一开始想遍历队列的,后来发现队列没办法遍历,汗-_-! 题意,给几个第一秒冲出的距离和以后速度,求每秒后最前面人的编号,求完后最前 ...
- HDU 1102 Constructing Roads, Prim+优先队列
题目链接:HDU 1102 Constructing Roads Constructing Roads Problem Description There are N villages, which ...
随机推荐
- sqlserver 创建索引
语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名)WITH FILLFACTOR = 填充因子值0~100GO /*实例*/ CREATE NONCLUSTERED INDEX ...
- 将Oracle JDBC驱动库安装到本地仓库
1.为了添加详细版本信息,先查看当前Oracle数据库版本 select * from v$version; 查询返回如下信息 BANNER ----------------------------- ...
- ubuntu查看硬件信息
1,外部探针probe sudo apt-get install hwinfo 执行hwinfo获取系统信息 --short
- HBase 3、HBase练习题
1.建立学生和课程表 要求:学生可以选择多个课程,每个课程可以被多个学生选择. 查询某个学生所选的所有课程列表 查询某个课程,的学生列表 学生可以修改所选的课程 方案:学生与课程之间是多对多关系,那可 ...
- JavaScript 运行机制详解:深入理解Event Loop
Philip Roberts的演讲<Help, I'm stuck in an event-loop>,详细.完整.正确地描述JavaScript引擎的内部运行机制. 一.为什么JavaS ...
- 浏览器缓存相关http头
近期看雅虎黄金34条,学习下优化站点性能的方法. 当中有一条:"为文件头指定Expires或Cache-Control",详细来说指对于静态内容:设置文件头过期时间Expires的 ...
- Spting使用memcached
applicationContext.xml配置文件: <?xml version="1.0" encoding="UTF-8"?> <bea ...
- AIX-vi操作-提示Unknown terminal type的问题解决方法
AIX-vi操作-提示Unknown terminal type的问题解决方法AIX Version 5.3$ vi /etc/profilelinux: Unknown terminal type[ ...
- stagefright框架(二)- 和OpenMAX的運作
Stagefright的編解碼功能是利用OpenMAX框架,而且用的還是OpenCORE之OMX的實作,我們來看一下Stagefright和OMX是如何運作的. (1) OMX_Init OMXCli ...
- WinForm实现窗体最小化后小图标在右边任务栏下
一 基本功能1. 首先新建一个窗体,然后拖入一个名为 NotifyIcon 的控件,名字我没有改,就那个名字 2. 我的应用程序下有些图标文件,这里我用这个图标,我选择 013.ico 3. 选择 ...