hdu4393Throw nails
来源:互联网 发布:淘宝帽子专卖店 编辑:程序博客网 时间:2024/06/04 19:17
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
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 <= 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
Huge input, scanf is recommended.
Huge output, printf is recommended.
Submit
Status
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 <= 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
Huge input, scanf is recommended.
Huge output, printf is recommended.
题目大意:给你i个人第一秒的速度f 和接下来每一秒的速度都为 一个定值 s,每秒被淘汰一个跑的最远的人,求从第一秒到最后一秒被淘汰人的顺序
思路:因为f最大值为500,而s最大值为100,所以可以开一个a[110]的优先队列数组f最大的先出队 f相同时位置较小的先出队然后两个从1到100枚举出最远的距离的那个出队,直接暴力就可以过了。
#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;struct node { int f;int pri;friend bool operator < (node a, node b){ if(a.f != b.f) return a.f<b.f; else return a.pri>b.pri;}};priority_queue<node> q[110];int main(){ int t, n, s, f,i,j,count = 1;;cin>>t;while (t--){ cin>>n;for(i =0; i< n;i++){ node d; scanf("%d %d",&f,&s); d.f=f; d.pri= i+1; q[s].push(d);}int e,k=0,ans;printf("Case #%d:\n",count++);for(i = 0; i < n;i++){ans = -1;int r = 51000; for(j = 1;j<=100;j++) { if(!q[j].empty()) { node a = q[j].top(); if(a.f+j*k==ans&&r>a.pri) { e =j; r = a.pri; } if(a.f+j*k > ans) { ans = a.f+j*k; e = j; r = a.pri; } } } node f = q[e].top(); printf("%d",f.pri); if(i != n-1)printf(" "); q[e].pop(); k++;}cout<<endl;}return 0;}
0 0
- hdu4393Throw nails
- hdu 4393 Throw nails
- hdu 4393 Throw nails
- HDU 4393 Throw nails
- hdu 4393 Throw nails
- UVa 11096 - Nails
- uva11096(Nails)
- ZOJ3675:Trim the Nails
- HDU 4393 Throw nails
- HDU 4393 Throw nails
- ZOJ 3675 Trim the Nails
- ZOJ 3675 Trim the Nails
- As hard as nails 难以相处
- ZOJ 3675 Trim the Nails 小水题
- ZOJ 3675(Trim the Nails)
- ZOJ 3675 Trim the Nails(DFS)
- UVA 11096 || Nails (计算凸包周长
- ZOJ 3675 Trim the Nails(bfs)
- java数组定义方式
- poj 1456 Supermarket (贪心+并查集)
- mac sdk manager 无法更新或下载慢
- zookeeper管理分布式数据
- C# 调用Oracle存储过程返回select数据集
- hdu4393Throw nails
- ubuntu goagent
- 搜索引擎广告的检索和匹配算法
- 编译gdb注意事项:一定要用一个干净的build文件夹
- Servlet编程知识
- OC基础笔记2
- 时间倒计时代码
- 数据库索引原理
- VS2010 LNK1123: 转换到COFF期间失败; 文件无效或损坏