HDU 4393 Throw nails (暴力加排序)
来源:互联网 发布:企业网络管理培训 编辑:程序博客网 时间:2024/06/05 00:30
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.
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.
Huge input, scanf is recommended.
Huge output, printf is recommended.
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.
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
23100 1100 23 10051 12 23 34 13 4
Sample Output
Case #1:1 3 2Case #2:4 5 3 2 1
题意: n个人跑步,求每一秒跑在最前面的人。每个人的第一秒的速度为f,之后的速度都为s。
直接模拟肯定超时,可以用优先队列来做,可是考虑第一秒的速度不大于500,那么过了501秒之后胜负就已经分出,前501秒暴力求解,之后按照501秒时的距离排序即可。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int MAX = 0x3f3f3f3f;int T, n;struct C { int f, s, d, p;} a[50005];int cmp (C x, C y) { if(x.d != y.d) return x.d > y.d; else return x.p < y.p;}int main(){ scanf("%d", &T); for(int ca = 1; ca <= T; ca++) { scanf("%d", &n); memset(a, 0, sizeof(a)); for(int i = 1; i <= n; i++) scanf("%d%d", &a[i].f, &a[i].s); for(int i = 1; i <= n; i++) a[i].p = i; printf("Case #%d:\n", ca); int ans = 0, pos; for(int i = 1; i <= n; i++) { a[i].d += a[i].f; if( a[i].d > ans ) { ans = a[i].f; pos = i; } } a[pos].d = MAX; printf("%d", pos); for(int i = 2; i <= min(502, n); i++) { ans = 0; for(int j = 1; j <= n; j++) { if(a[j].d == MAX) continue; a[j].d += a[j].s; if( a[j].d > ans ) { ans = a[j].d; pos = j; } } a[pos].d = MAX; printf(" %d", pos); } sort(a+1, a+1+n, cmp); for(int i = 503; i <= max(n, 502); i++) printf(" %d", a[i].p); printf("\n"); } return 0;}
0 0
- HDU 4393 Throw nails (暴力加排序)
- hdu 4393 Throw nails
- hdu 4393 Throw nails
- HDU 4393 Throw nails
- hdu 4393 Throw nails
- HDU 4393 Throw nails
- HDU 4393 Throw nails
- HDU 4393 Throw nails (STL)
- HDU 4393 Throw nails(技巧性模拟)
- HUD4393 Throw nails(思维模拟)
- hdu 4393 Throw nails 相同的状态做相同的处理 贪心
- Throw nails hdu多校联赛10 1004 水题
- HDOJ 4393 Throw nails —— 思维题
- hdu4393 Throw nails【优先队列&&贪心&&模拟】
- HDU - 4277(暴力加+hash)
- uva11096(Nails)
- HDU 5745(暴力)
- HDU 5762(暴力)
- PHP引用操作以及外部操作函数的局部静态变量的方法
- uva 1521 - GCD Guessing Game(贪心)
- s5pv210 芯片 tiny210 板 网卡启动流程
- cocos2d-x3.1.1 step by step 学习笔记6 Sprite精灵类
- 黑马程序员_IO
- HDU 4393 Throw nails (暴力加排序)
- POJ3624_Charm Bracelet(背包/01背包)
- rt5350 sn9c291 ov9712 录像H264
- 详解FindBugs的各项检测器
- OC (七)
- Android开发 --- 使用百度地图API (3.0版本)
- 编写一个程序,程序中要调用名为one_three ();函数,······
- Java toString()的用法
- POJ 3895 Cycles of Lanes