G - Throw nails
来源hde4393
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 <= 20), indicates the number of test cases.
In each case, the first line contains one integer n (1 <= n <= 50000), which is the number of the players.
Then n lines follow, each contains two integers Fi(0 <= Fi <= 500), Si (0 < Si <= 100) 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 1.
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
2
3
100 1
100 2
3 100
5
1 1
2 2
3 3
4 1
3 4
Sample Output
Case #1:
1 3 2
Case #2:
4 5 3 2 1
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!!)
因为只有500初始位置,先排500次,剩下的按速度,按初始位置,按id排就可以
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=3e2+10;
struct peo
{
int speed,pos,id,visit;
}a[50005];
bool cmp(peo a,peo b)
{
if(a.visit!=b.visit)
return a.visit>b.visit;
if(a.speed!=b.speed)
return a.speed>b.speed;
if(a.pos!=b.pos)
return a.pos>b.pos;
return a.id<b.id;
}
void solve(int cas,int n)
{
pf("Case #%d:\n",cas);
int ans=0,Max=0;
rep(i,0,min(n,502))
{
Max=0;
rep(j,0,n)
{
if(a[j].visit==0)
if(a[j].pos+a[j].speed*i>Max)
{
Max=a[j].pos+a[j].speed*i;
ans=j;
}
}
if(i==0)
pf("%d",a[ans].id);
else
pf(" %d",a[ans].id);
a[ans].visit=1;
}
if(n<=502)
{
pf("\n");return;
}
sort(a,a+n,cmp);
rep(i,502,n)
pf(" %d",a[i].id);
pf("\n");
}
int main()
{
int re,cas=1;;
scf(re);
while(re--)
{
int id=1,n;
scf(n);
rep(i,0,n)
{
a[i].visit=0;
a[i].id=id++;
scff(a[i].pos,a[i].speed);
}
solve(cas++,n);
}
return 0;
}
G - Throw nails的更多相关文章
- HDU 4393 Throw nails
Throw nails Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)
...
- hdu 4393 Throw nails(STL之优先队列)
Problem Description The annual school bicycle contest started. ZL is a student in this school. He is ...
- 刷题总结——Throw nails(hdu4393)
题目: Problem Description The annual school bicycle contest started. ZL is a student in this school. H ...
- 【HDOJ】4393 Throw nails
水题,优先级队列. /* 4393 */ #include <iostream> #include <sstream> #include <string> #inc ...
- 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个人,拥有最初速度 ...
- C++异常处理:try,catch,throw,finally的用法
写在前面 所谓异常处理,即让一个程序运行时遇到自己无法处理的错误时抛出一个异常,希望调用者可以发现处理问题. 异常处理的基本思想是简化程序的错误代码,为程序键壮性提供一个标准检测机制. 也许我们已经使 ...
- C++异常处理: try,catch,throw,finally的用法
写在前面 所谓异常处理,即让一个程序运行时遇到自己无法处理的错误时抛出一个异常,希望调用者可以发现处理问题. 异常处理的基本思想是简化程序的错误代码,为程序键壮性提供一个标准检测机制. 也许我们已经使 ...
随机推荐
- E. Thematic Contests 二分,离散化
题目意思是给你n个问题即数字,n的大小代表问题所在的话题,题目要求举办多场比赛,每场比赛的只能一种问题,且后一场比赛的问题必须是前一场的两倍,求举办比赛可能最多的问题总数 传送门 解题思路:将出现每种 ...
- [原创]浅谈移动互联网App兼容性测试
[原创]浅谈移动互联网App兼容性测试 今天要谈的话题,估计各位测试都有感受,移动互联网App兼容性测试,我们到底测试覆盖如何去挑选机型?具体移动App兼容性测试如何开展?是不是应引进像testin这 ...
- securecrt通过ssh连接板子: 密钥交换失败,没有兼容的加密程序
在用securecrt连接板子时遇到如下问题: 需要修改板子上的/etc/ssh/ssh_config和/etc/ssh/sshd_config. 修改/etc/ssh/ssh_config,取消下面 ...
- linux下修改/dev/shm tmpfs文件系统大小
默认系统就会加载/dev/shm ,它就是所谓的tmpfs,有人说跟ramdisk(虚拟磁盘),但不一样.象虚拟磁盘一样,tmpfs 可以使用您的 RAM,但它也可以使用您的交换分区来存储.而且传统的 ...
- PDF.js实现个性化PDF渲染(文本复制)
我肥来啦
- 图解 Git
https://juejin.im/entry/5917c463da2f60005de84195
- Grafana数据可视化
1.1 Grafana简介 1.1.1 Grafana是什么? 一个类似Kibana的东西,也是对后端的数据进行实时展示,那么Grafana和Kibana有什么区别?在我看来区别不大,不过在大家的日常 ...
- gitlab配置通过smtp发送邮件(QQ exmail腾讯企业为例)
gitlab配置通过smtp发送邮件(QQ exmail腾讯企业为例) 首先祭出官网文档链接:https://docs.gitlab.com/omnibus/settings/smtp.html 其实 ...
- DLLImport的用法C#
它来调用WIN32的API或者调用一下C或C++编写的DLL.使用实例:将编译好的C++ DLL拷贝到BIN目录(DLLImport会从程序启动目录BIN开始查找相应名称的DLL,未找到则转至syst ...
- ionic1页面切换动画卡顿优化
https://github.com/shprink/ionic-native-transitions https://www.npmjs.com/package/ionic-native-trans ...