来源hde4393

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

The first case:

1st Second end

Player1 100m (BOOM!!)

Player2 100m

Player3 3m

2nd Second end

Player2 102m

Player3 103m (BOOM!!)

3rd Second end

Player2 104m (BOOM!!)

因为只有500初始位置,先排500次,剩下的按速度,按初始位置,按id排就可以

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=3e2+10;
struct peo
{
int speed,pos,id,visit;
}a[50005];
bool cmp(peo a,peo b)
{
if(a.visit!=b.visit)
return a.visit>b.visit;
if(a.speed!=b.speed)
return a.speed>b.speed;
if(a.pos!=b.pos)
return a.pos>b.pos;
return a.id<b.id;
}
void solve(int cas,int n)
{
pf("Case #%d:\n",cas);
int ans=0,Max=0;
rep(i,0,min(n,502))
{
Max=0;
rep(j,0,n)
{
if(a[j].visit==0)
if(a[j].pos+a[j].speed*i>Max)
{
Max=a[j].pos+a[j].speed*i;
ans=j;
}
}
if(i==0)
pf("%d",a[ans].id);
else
pf(" %d",a[ans].id);
a[ans].visit=1;
}
if(n<=502)
{
pf("\n");return;
}
sort(a,a+n,cmp);
rep(i,502,n)
pf(" %d",a[i].id);
pf("\n");
} int main()
{
int re,cas=1;;
scf(re);
while(re--)
{
int id=1,n;
scf(n);
rep(i,0,n)
{
a[i].visit=0;
a[i].id=id++;
scff(a[i].pos,a[i].speed);
}
solve(cas++,n);
}
return 0;
}

G - Throw nails的更多相关文章

  1. HDU 4393 Throw nails

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

  2. hdu4393 Throw nails(只用模拟前面500来次,后面根据速度、位置、id值排序即可)

                                                                                                         ...

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

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

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

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

  5. 【HDOJ】4393 Throw nails

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

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

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

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

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

  8. C++异常处理:try,catch,throw,finally的用法

    写在前面 所谓异常处理,即让一个程序运行时遇到自己无法处理的错误时抛出一个异常,希望调用者可以发现处理问题. 异常处理的基本思想是简化程序的错误代码,为程序键壮性提供一个标准检测机制. 也许我们已经使 ...

  9. C++异常处理: try,catch,throw,finally的用法

    写在前面 所谓异常处理,即让一个程序运行时遇到自己无法处理的错误时抛出一个异常,希望调用者可以发现处理问题. 异常处理的基本思想是简化程序的错误代码,为程序键壮性提供一个标准检测机制. 也许我们已经使 ...

随机推荐

  1. Mac安装Linux的KVM管理工具virt-manager

    安装: brew tap jeffreywildman/homebrew-virt-manager brew install virt-manager virt-viewer 中途会碰到很多问题,可以 ...

  2. pygame-KidsCanCode系列jumpy-part9-使用spritesheet

    做过前端的兄弟应该都知道css sprite(也称css精灵),这是一种常用的减少http请求次数的优化手段.把很多小图拼成一张大图,只加载1次,然后用css定位到不区的区域,从而展示不同的图片.游戏 ...

  3. delphi ListView 设置固定列宽

    object Form1: TForm1 Left = Top = Caption = 'Form1' ClientHeight = ClientWidth = Color = clBtnFace F ...

  4. Spring Boot 中application.yml与bootstrap.yml的区别

    其实yml和properties文件是一样的原理,且一个项目上要么yml或者properties,二选一的存在. 推荐使用yml,更简洁. bootstrap与application1.加载顺序这里主 ...

  5. Spring Boot tomcat

    定制内嵌 Tomcat 设置内嵌Tomcat的端口 Spring Boot 内嵌的 Tomcat 服务器默认运行在 8080 端口.如果,我们需要修改Tomcat的端口,我们可以在 src/main/ ...

  6. ThunderBird对只有回复地址的邮件过滤

    回复地址,其实就是reply-to 增加一个自定义的字段:reply-to即可

  7. C# System.IO.FileMode

    字段 Append 6 若存在文件,则打开该文件并查找到文件尾,或者创建一个新文件. 这需要 Append 权限. FileMode.Append 只能与 FileAccess.Write 一起使用. ...

  8. 面试汇总——说一下CSS盒模型

    本文是面试汇总分支——说一下CSS盒模型. 基本概念:W3C标准盒模型和IE盒模型 CSS如何设置这两种模型 JS如何获取盒模型对应的宽和高 根据盒模型解释边距重叠 BFC(边距重叠解决方案) 一. ...

  9. N-gram的简单的介绍

    目录: 1. 联合概率 2. 条件概率 3. N-gram的计算方式 4. 评估N-gram的模型. 前言: N-gram是机器学习中NLP处理中的一个较为重要的语言模型,常用来做句子相似度比较,模糊 ...

  10. Spring Boot系列——AOP配自定义注解的最佳实践

    AOP(Aspect Oriented Programming),即面向切面编程,是Spring框架的大杀器之一. 首先,我声明下,我不是来系统介绍什么是AOP,更不是照本宣科讲解什么是连接点.切面. ...