HDU 4393 Throw nails

Throw nails

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1729    Accepted Submission(s): 538

Problem 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.

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

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!!)

Source

2012 Multi-University Training Contest 10

解析:直接暴力搜索会超时,我们可以对数据进行预处理,提高效率。考虑到0 < Si <= 100,我们可以构造一个按Si分类的优先队列数组。每个优先队列的数据按Fi进行一级排序, 按ID进行二级排序。这样处理之后,每一秒应该出局的运动员必然在所有优先队列的队首元素中产生。我们可以枚举时间,对这个优先队列数组进行遍历,即每一秒在最多100个运动员中进行选择,找到该秒下应该出局的运动员,不断输出即可。

 1 #include <cstdio>
 2 #include <queue>
 3 using namespace std;
 4
 5 struct node{
 6     int f,id;
 7     bool operator<(const node& tmp)const
 8     {
 9         if(f != tmp.f) return f<tmp.f;
10         return id>tmp.id;
11     }
12 };
13
14 priority_queue<node> q[105];
15
16 int main()
17 {
18     int t,n,cn = 0;
19     scanf("%d",&t);
20     while(t--){
21         scanf("%d",&n);
22         for(int i = 1; i <= n; ++i){
23             node tmp;
24             int Si;
25             scanf("%d%d",&tmp.f,&Si);
26             tmp.id = i;
27             q[Si].push(tmp);
28         }
29         printf("Case #%d:\n",++cn);
30         for(int i = 1; i <= n; ++i){
31             int res;
32             int maxdis = -1;
33             int minid = 0x7fffffff;
34             for(int j = 1; j <= 100; ++j){
35                 if(!q[j].empty()){
36                     int dis = q[j].top().f+(i-1)*j;
37                     if(dis>maxdis || (dis == maxdis && q[j].top().id<minid)){
38                         maxdis = dis;
39                         minid = q[j].top().id;
40                         res = j;
41                     }
42                 }
43             }
44             if(i != n)
45                 printf("%d ",q[res].top().id);
46             else
47                 printf("%d\n",q[res].top().id);
48             q[res].pop();
49         }
50     }
51     return 0;
52 }
时间: 2024-10-24 06:53:52

HDU 4393 Throw nails的相关文章

HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A few naked children throw stones standing on the same position, the one throws farther win the game. Aha, of course, there are some naughty boys who care

HDU 4782 Beautiful Soup(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4782 Problem Description Coach Pang has a lot of hobbies. One of them is playing with "tag soup" with the help of Beautiful Soup. Coach Pang is satisfied with Beautiful Soup in every respect, except

HDU 2669 Romantic(扩展欧几里德)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees are Shaking, Leaves are Falling. Lovers Walk passing, and so are You. ..........

2016CCPC东北地区大学生程序设计竞赛 - 重现赛 1008(hdu 5929)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5929 Problem Description Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operations of stack: ? PUSH x: put x on the top of the stack, x must be 0 or 1.? POP

HDU 2669 Romantic

Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees are Shaking, Leaves are Falling. Lovers Walk passing, and so are You. ................................Write in English class by yifenfei Gir

hdu 2669

Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees are Shaking, Leaves are Falling. Lovers Walk passing, and so are You. ................................Write in English class by yifenfei Gir

hdu 5047 Sawtooth--2014acm上海赛区邀请赛(附java模板)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 Sawtooth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 377    Accepted Submission(s): 116 Problem Description Think about a plane: ● One st

HDU 3507 Print Article 斜率优化

Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 4810    Accepted Submission(s): 1451 Problem Description Zero has an old printer that doesn't work well sometimes. As it is antique

hdu 2490 队列优化dp

http://acm.hdu.edu.cn/showproblem.php?pid=2490 Parade Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1145    Accepted Submission(s): 527 Problem Description Panagola, The Lord of city F likes t