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. 使用sp_configure启用 'Ad Hoc Distributed Queries'

    使用sp_configure启用 'Ad Hoc Distributed Queries' 原文地址:http://blog.sina.com.cn/s/blog_531bb7630100xh88.h ...

  2. UESTC_邱老师的脑残粉 2015 UESTC Training for Graph Theory<Problem D>

    D - 邱老师的脑残粉 Time Limit: 12000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

  3. Windows Azure功能更新:Oracle软件正式登陆Azure了

    今天,Windows Azure国际版发布了新的功能:全面支持Oracle软件,包括Oracle Linux, Oracle 12c数据库,Weblogic 11g和12c,Oracle JDK 6和 ...

  4. http://home.cnblogs.com/

    说起编辑器,可能大部分人要推荐的是Vim和Emacs,本人用过Vim,功能确实强大,但是不是很习惯,之前一直有朋友推荐SUblime Text 2这款编辑器,然后这段时间就试了一下,就深深地喜欢上这款 ...

  5. magento后台登陆后,没任何提示,又跳转到登陆页面

    这个问题通常是cookie配置的问题.需要去将core_config_data中web/cookie/cookie_path.web/cookie/cookie_domain设为null

  6. nsinteger 与 int 区别

    在苹果的api实现中,NSInteger是一个封装,它会识别当前操作系统的位数,自动返回最大的类型.   当你不知道你的操作系统是什么类型的时候,你通常会想要使用NSInteger,所以或许你想要你的 ...

  7. SQL Server 日期函数:某天是星期几?

    [鹏城万里] 发表于 www.sqlstudy.com 要得到某一天是星期几,需要用到 SQL Server 中的日期函数:datename(). 今天是星期几,例子 1: set language ...

  8. 让你的javascript函数拥有记忆功能,降低全局变量的使用

    考虑例如以下场景:假如我们须要在界面上画一个圆,初始的时候界面是空白的.当鼠标移动的时候,圆须要尾随鼠标移动.鼠标的当前位置就是圆心.我们的实现方案是:假设界面上还没有画圆,那么就新创建一个:假设已经 ...

  9. swift通过摄像头读取每一帧的图片,并且做识别做人脸识别

    最近帮别人做一个项目,主要是使用摄像头做人脸识别 github地址:https://github.com/qugang/AVCaptureVideoTemplate 要使用IOS的摄像头,需要使用AV ...

  10. 11个有用的移动网页开发App和HTML5框架

    在过去的两年里,触屏设备飞速增长.iOS和Android设备让开发者和设计师开始重新思考他们的网页应用,以提供更好的触屏体验. 移动Web应用相对于本地的App有很多优势,虽然也有很多设计和开发上的挑 ...