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<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iterator>
#include<utility>
#include<sstream>
#include<iostream>
#include<cmath>
#include<stack>
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<t.id; //id
}
};
vector<node> 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<sum[j]) Max=sum[j],choose=j;
}
vis[choose]=true;
if(kase++) printf(" ");
printf("%d",choose);
}
save.clear();
for(int i=1;i<=N;i++) if(!vis[i]) save.push_back(node(sum[i],speed[i],i)); // 剩余的选手
sort(save.begin(),save.end());
for(int i=0;i<save.size();i++)
{
if(kase++) printf(" ");
printf("%d",save[i].id);
}
printf("\n");
}
return 0;
}
 
 

hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)的更多相关文章

  1. HDU 4393 Throw nails

    Throw nails Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. 刷题总结——Throw nails(hdu4393)

    题目: Problem Description The annual school bicycle contest started. ZL is a student in this school. H ...

  3. HDU 4393 Throw nails(贪心加模拟,追及问题)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115361#problem/D 题意大致是:给出最多50000个人,拥有最初速度 ...

  4. G - Throw nails

    来源hde4393 The annual school bicycle contest started. ZL is a student in this school. He is so boring ...

  5. hdu 4393 Throw nails(STL之优先队列)

    Problem Description The annual school bicycle contest started. ZL is a student in this school. He is ...

  6. 【HDOJ】4393 Throw nails

    水题,优先级队列. /* 4393 */ #include <iostream> #include <sstream> #include <string> #inc ...

  7. HDU 4393 Throw nails(优先队列)

    优先队列的应用 好坑,好坑,好坑,重要的事情说三遍! #include<iostream> #include<cstdio> #include<cstring> # ...

  8. 在线判题 (模拟)http://202.196.1.132/problem.php?id=1164

    #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #de ...

  9. 【noip模拟赛4】找啊找啊找BF 拓扑排序

    描述 sqybi上次找GF的工作十分不成功,于是依旧单身的他在光棍节前的某天突发奇想,要给自己找一个BF(这里指的是男性的好朋友……),这样既可以和人分享内心的压抑(路人甲:压抑还分享么……),也可以 ...

随机推荐

  1. 【剑指offer】面试题27:二叉搜索树与双向链表

    题目: 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向. 思路: 假设已经处理了一部分(转换了左子树),则得到一个有序的双向链表,现在 ...

  2. Unity 脚本函数生命周期

    Awake(),一般我们在这里做一些组件的获得,比如使用getcomponent方法. Start(),我们可以在这里给变量赋值. FixUpdate(),固定更新,因为这里得更新速度为固定(可以在T ...

  3. 更改debian的软件源sources.list

    之前debian6这系统是在公司装的.公司有百兆光纤,多线接入,就随便选了个源,也没多大问题.现在回到家里变成了2M的ADSL,很多软件更新不下来. 更改软件源,也就修改/etc/apt/source ...

  4. VIm变成sublime (转)

    sublime在ubuntu下始终支持不是很好, 特别是对中文输入的支持,还有一些插件在ubuntu下也不能用. 在ubuntu下还是用vim吧.  我们一起把vim变成sublime. 只需要三步 ...

  5. XSS第二节,XSS左邻右舍

    昨天的文章中引用了OWASP2013年的江湖排名,今天来看一下TOP中XSS的左邻右舍都是谁,先看一下他们的大名,再进一步介绍 [以下主要翻译自https://www.owasp.org/index. ...

  6. eclipse里添加类似myeclipse打开当前操作目录

    1.开打eclipse ide,依次run->external tools->external tools configuration 2.在Program下,new一个自己定义的prog ...

  7. java遍历泛型的方法

    一.List遍历 Java中List遍历有三种方法来遍历泛型,主要为: 1.for循环遍历 2.iterator遍历 3.foreach遍历 package com.gmail.lsgjzhuwei; ...

  8. jQuery validate 的valid()方法一直返回true

    1 调用$('#myForm').valid(),一直返回ture eg:html <form id="myForm"> <input class="f ...

  9. 使用react-native做一个简单的应用-05 navigator的使用

    今天生病了,难受... Navigator顾名思义就是导航器的意思. 在Android和iOS中,导航器的样式是不一样的 ,有一个比较好的网址可以提供大家学习(网址),由于样式的不统一,于是我决定自己 ...

  10. Installing the Eclipse Plugin

    Installing the Eclipse Plugin Android offers a custom plugin for the Eclipse IDE, called Android Dev ...