Problem Description
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.
Input
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.
Hint

Huge input, scanf is recommended.
Huge output, printf is recommended.

 
Output
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.
 
Sample Input

 
Sample Output
Case #:

Case #:
    
Hint

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!!)

 
Source
 
 
这道题要用优先队列来解决。
首先定义一个优先队列,类型为Node,Node里面有两个参数f和index,f表示当前的距离,index表示下标。在Node里面排序(如果f大则优先,如果f相等则下标小的优先)
优先队列的数量100个就够了,因为s最大才100.
然后就是两个for循环,第一个for循环0~n-1,表示一共要淘汰n次,且这个循环的i可以表示当前时间的秒数供下面计算距离
第二个for循环j表示s,范围为1~100,条件是q[j].empty()==0.找出最大的距离。id表示s,如果有多个最大的距离相等,id表示最小的s。
输出printf("%d",q[id].top().index);然后q[id].pop();即可
有够详细了。
 #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之优先队列)的更多相关文章

  1. HDU 4393 Throw nails

    Throw nails Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. HDU 4393 Throw nails(优先队列)

    优先队列的应用 好坑,好坑,好坑,重要的事情说三遍! #include<iostream> #include<cstdio> #include<cstring> # ...

  3. HDU 4393 Throw nails(贪心加模拟,追及问题)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115361#problem/D 题意大致是:给出最多50000个人,拥有最初速度 ...

  4. 【HDOJ】4393 Throw nails

    水题,优先级队列. /* 4393 */ #include <iostream> #include <sstream> #include <string> #inc ...

  5. STL之优先队列

    STL 中优先队列的使用方法(priority_queu) 基本操作: empty() 如果队列为空返回真 pop() 删除对顶元素 push() 加入一个元素 size() 返回优先队列中拥有的元素 ...

  6. hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)

                                                                                                         ...

  7. HDOJ(HDU).1412 {A} + {B} (STL SET)

    HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...

  8. hdu 4393 优先队列

    用优先队列储存每个人的初始距离和编号,每轮求出最快的人,然后pop掉 一开始想遍历队列的,后来发现队列没办法遍历,汗-_-! 题意,给几个第一秒冲出的距离和以后速度,求每秒后最前面人的编号,求完后最前 ...

  9. HDU 1102 Constructing Roads, Prim+优先队列

    题目链接:HDU 1102 Constructing Roads Constructing Roads Problem Description There are N villages, which ...

随机推荐

  1. JNI与JNA性能比较

    JNI与JNA性能比较 在介绍JNA时,提到了JNA是基于JNI的,是在JNI上封装了一层,JNI性能不如JNA.最近在网上看到篇简单的比较这两者性能的文档,感觉不错,现转载一下: 分别用JNI和JN ...

  2. Java中取小数点后两位(四种方法)

    摘自http://irobot.iteye.com/blog/285537 Java中取小数点后两位(四种方法)   一 Long是长整型,怎么有小数,是double吧     java.text.D ...

  3. javax.mail用smtp服务器发送带附件的邮件

    jar包: javax.mail-1.5.5.jar maven配置: <dependency> <groupId>com.sun.mail</groupId> & ...

  4. char与byte的差别

    非常多刚開始学习的人(包含我,已经学了一年多java了)肯会对char和byte这两种数据类型有所疑惑,相互混淆,今天特地查了好多资料,对byte和char两种数据类型进行了总结和比較,先将结果与大家 ...

  5. 命令行分析java线程CPU占用

    1.使用top命令找出占用cpu最高的JAVA进程pid号 2. 找出占用cpu最高的线程: top -Hp  -n 1 3. 打印占CPU最高JAVA进程pid的堆栈信息 jstack pid &g ...

  6. 图像处理中像素点的问题:unsigned char 和 char

    以前在做图像处理的时候,一直不太在意这个问题,对图像每个像素点的灰度值,总是认为char也可,unsigned char也可.尽管它们都是8位,但是表示的数的范围却不相同:char: -128~127 ...

  7. 字符串最小表示法 O(n)算法

    网上看了这篇文章后还是感觉有些地方讲的没有详细的证明所以添加了一点 红色字是博主写的 求字符串的循环最小表示: 上面说的两个字符串同构的,并没有直接先求出Min(s),而是通过指针移动,当某次匹配串长 ...

  8. 淘宝开源任务调度框架tbschedule

    背景 分布式任务调度是非常常见的一种应用场景,一般对可用性和性能要求不高的任务,采用单点即可,例如linux的crontab,spring的quarz,但是如果要求部署多个节点,达到高可用的效果,上面 ...

  9. MySQL整数类型说明 int(11) vs int(20)

    整数类型后面跟的是显示的宽度.M指示最大显示宽度.最大有效显示宽度是255.显示宽度与存储大小或类型包含的值的范围无关. 实践出真知: mysql> create table test2 ( a ...

  10. PL/SQL分页查询

    create or replace procedure fenye(tabelname in varchar2,currentpage in number,pageSize in number,inW ...