HDU 4393 Throw nails(技巧性模拟)
来源:互联网 发布:jdbc连接数据库 编辑:程序博客网 时间:2024/05/29 08:23
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.
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.
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.
23100 1100 23 10051 12 23 34 13 4
Case #1:1 3 2Case #2:4 5 3 2 1
HintThe first case:1st Second endPlayer1 100m (BOOM!!)Player2 100mPlayer3 3m2nd Second endPlayer2 102m Player3 103m (BOOM!!)3rd Second endPlayer2 104m (BOOM!!)
题解:
题意:
有n个人跑步,每一秒你要给跑在最前撒钉子,boom,如果有多个人就boom掉编号最小的,每boom掉一个人输出他的编号
思路:
一开始用数组模拟,每次写一个带变量的cmp+sort排序华丽得tle了2发,冷静下来,其实这题由于初始值是500最大,所以两个人之间的差距最大也就是500,一个人的速度最小是那1,那么过501秒后是不是胜负已分,落后的再也追不上前面的了呢,所以就用带点技巧模拟前501s的情况,然后后面的只要按照501s的时候的排名输出就行了,不必再模拟下去了
代码:
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>using namespace std;#define lson k*2#define rson k*2+1#define M (t[k].l+t[k].r)/2#define ll long long#define INF 10086111int t;struct node{ int s; int v; int index; friend bool operator<(node x,node y)//用于501s后的排序,不同路程路程长的在前,相同路程标号小的在前 { if(x.s==y.s) return x.index<y.index; return x.s>y.s; }}a[50005];int n;int find()//查找一个最大的index{ int i,maxx=-1,index=1008611,p; for(i=0;i<n;i++) { if(maxx<a[i].s||(maxx==a[i].s&&a[i].index<index))//我wa了2发就是这个,标号小的等值也是要替换的 { p=i; maxx=a[i].s; index=a[i].index; } a[i].s+=a[i].v; } if(p!=n-1)//把该节点换到最后 swap(a[p],a[n-1]); n--;//数组大小--,每次查找就会快一些 return index;}int main(){int m,i,j;int test,p,size;node now;while(scanf("%d",&test)!=EOF) { for(p=1;p<=test;p++) { scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d%d",&a[i].s,&a[i].v); a[i].index=i+1; } printf("Case #%d:\n",p); printf("%d",find()); t=0; while(n>0&&t<502)//模拟前502s的情况。。501貌似也可以 { printf(" %d",find()); t++; } if(n>0)//如果n还大于0,直接sort一遍输出 { sort(a,a+n); for(i=0;i<n;i++) { printf(" %d",a[i].index); } } 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(思维模拟)
- hdu4393 Throw nails【优先队列&&贪心&&模拟】
- HDU 5491 The Next(技巧性模拟)
- hdu 4393 Throw nails 相同的状态做相同的处理 贪心
- HDU 3717 Rescue(二分+技巧性模拟)【详解】
- Throw nails hdu多校联赛10 1004 水题
- HDOJ 4393 Throw nails —— 思维题
- HDU 4288 Coder (技巧性暴力模拟+二分||线段树+离线操作)
- uva11096(Nails)
- 1.4、solrj的使用_代码开始
- selinux
- 多线程实现间隔打印
- SAS BASE&SAS EM 关联分析的学习 proc dmdb and proc assoc
- Python 练习实例6
- HDU 4393 Throw nails(技巧性模拟)
- POSIX和System V的比较/IPC函数汇总
- Android 二次封装网络加载框架
- 四、枚举,递推、迭代法初步学习
- 选择文件与获取选中文件绝对路径
- scrapy shell 爬取一些网站不响应
- idea中导入maven项目时修改maven地址
- LeetCode——Linked List Cycle
- C语言“翻译”C++结构体中的成员函数