博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)
阅读量:5323 次
发布时间:2019-06-14

本文共 2815 字,大约阅读时间需要 9 分钟。

                                                                                                              
Throw nails
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
 
题意:有N个人跑步比赛,刚开始都有起始位置s和速度f,每秒淘汰一名选手(起始是第1秒,也算),淘汰跑在最前面的,如果有多个人跑在前面,则淘汰id值最小的。
解析:由于N很大,不可能每秒都模拟,但关注一下数据,起始位置s很小,想象一下,如果a的速度比b的速度多1,那么500+秒后不管a和b的起始位置如何,a一定在b前面。所以最多只用模拟前500秒(如果想保险,可以多加几次),如果还有剩下的选手,先按他们的速度排序,如果两个人的速度相同,则比较他们的当前的位置,否则比较id.
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; const int INF=1000000007; const double eps=0.00000001; const int maxn=50005; int loc[maxn],speed[maxn]; int sum[maxn]; bool vis[maxn]; struct node { int now,s,id; node(int now=0,int s=0,int id=0):now(now),s(s),id(id){} bool operator < (const node& t) const { if(s!=t.s) return s>t.s; //比较速度 if(now!=t.now) return now>t.now; //当前位置 return id
save; int main() { int T,Case=0; cin>>T; while(T--) { int N; cin>>N; for(int i=1;i<=N;i++) { scanf("%d%d",&loc[i],&speed[i]); sum[i]=loc[i]-speed[i]; //由于起始也要淘汰一名选手,所以先减掉,到后面开始模拟时加上即可 } printf("Case #%d:\n",++Case); memset(vis,false,sizeof(vis)); int kase=0; //方便打印加的一个标记 for(int i=1;i<=min(N,550);i++) //N可能比550小 { int choose=-1,Max=-INF; for(int j=1;j<=N;j++) { if(vis[j]) continue; sum[j]+=speed[j]; if(Max

转载于:https://www.cnblogs.com/wust-ouyangli/p/4765468.html

你可能感兴趣的文章
iOS如何过滤掉文本中特殊字符
查看>>
基础学习:C#中float的取值范围和精度
查看>>
javaagent 简介
查看>>
python升级安装后的yum的修复
查看>>
Vim配置Node.js开发工具
查看>>
web前端面试题2017
查看>>
ELMAH——可插拔错误日志工具
查看>>
MySQL学习笔记(四)
查看>>
【Crash Course Psychology】2. Research & Experimentation笔记
查看>>
两数和
查看>>
移动设备和SharePoint 2013 - 第3部分:推送通知
查看>>
SOPC Builder中SystemID
查看>>
MySQL数据库备份工具mysqldump的使用(转)
查看>>
NTP服务器配置
查看>>
关于 linux 的 limit 的设置
查看>>
HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)
查看>>
vim中文帮助教程
查看>>
MySQL基础3
查看>>
RxJS & Angular
查看>>
面向对象(多异常的声明与处理)
查看>>