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 ...
随机推荐
- JS Message 网页消息提醒
JS message是一个非常小的(用gzip压缩之后才3kb)JavaScript library 用于轻松在网页上展示通知提醒.除了通知,它还支持创建带风格的对话框和确认对话框.不需要任何JS框架 ...
- IP、路由配置
IP地址组成: 网络地址主机地址32位二进制 A类: 255.0.0.0, 8: 0 000 0001 - 0 111 1111 127个A类,127用于回环,1-126 2^7- ...
- Impala 1、Impala理论
1.Impala简介 • Cloudera公司推出,提供对HDFS.Hbase数据的高性能.低延迟的交互式SQL查询功能. • 基于Hive使用内存计算,兼顾数据仓库.具有实时.批处理.多并发等优点 ...
- PHP MySQL Where 子句 之Where
WHERE 子句 如需选取匹配指定条件的数据,请向 SELECT 语句添加 WHERE 子句. 语法 SELECT column FROM table WHERE column operator va ...
- 利用Python完成一个小游戏:随机挑选一个单词,并对其进行乱序,玩家要猜出原始单词
一 Python的概述以及游戏的内容 Python是一种功能强大且易于使用的编程语言,更接近人类语言,以至于人们都说它是“以思考的速度编程”:Python具备现代编程语言所应具备的一切功能:Pytho ...
- mysql的基本使用方法
创建数据库:create database [if not exist]name [character set 编码方式 collate 校对规则] 显示库的创建信息:show create data ...
- Oracle SQL函数之聚组函数
AVG([distinct|all]x) [功能]统计数据表选中行x列的平均值. [参数]all表示对所有的值求平均值,distinct只对不同的值求平均值,默认为all 如果有参数distinct或 ...
- 【高精度递推】【HDU1297】Children’s Queue
Children's Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 转载-SQL不同服务器数据库之间的数据操作整理(完整版) .
---------------------------------------------------------------------------------- -- Author : htl25 ...
- C++ primer学习记录(个人猜想未测试版本)
学习版本:第五版. 本博文主要记录个人曾经并不知晓知识细节. 因为linux下的编译环境还未进行学习.所以实际代码测试将在今后完成. 红色:需确认. 蓝色:重点. 1)const对象设定为仅在文件内有 ...