HDU 4393 Throw nails (simple question)

Source: Internet
Author: User
Throw nails

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

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

 

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

 

OutputFor 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 Input2 3 100 1 100 2 3 100 5 1 1 2 2 3 3 4 1 3 4

 

Sample OutputCase #1: 1 3 2 Case #2: 4 5 3 2 1

Hint

Hint The first case: 1st Second end Player1 100 m (BOOM !!) Player2 100 m Player3 3 m 2nd Second end Player2 102 m Player3 103 m (BOOM !!) 3rd Second end Player2 104 m (BOOM !!)

 

 

Source2012 Multi-University Training Contest 10

 

Recommendzhuyuanchen520

 

Statistic | Submit | Discuss | Note

 

 

 

 

 

The main idea is to think about it carefully.

F <= 500, S <= 100

My practice is to put all the same speed in a priority queue. The priority queue is first sorted by F from large to small, and F is the same, then sorted by serial number from small to large.

Then, find the farthest team from the top of the queue each time.

 

Another way is to consider F <= 500, so F has no effect after 50 S, which is entirely determined by S.

Therefore, it can be brute-force to 500 s, and then output from large to small according to the size of S.

 

 

/* HDU 4393G + + 406 ms 1044 K */# include <stdio. h >#include <iostream >#include <queue> # include <algorithm> using namespace std; struct Node {int F; int index; friend bool operator <(Node, node B) {if (. f! = B. f) return. F <B. f; // the priority of F is higher than that of else return. index> B. index; // high priority of a small index }}; priority_queue <Node> q [110]; int main () {// freopen ("in.txt", "r ", stdin); // freopen ("out.txt", "w", stdout); int T; int iCase = 0; int n; Node a; int S; scanf ("% d", & T); while (T --) {iCase ++; scanf ("% d", & n); for (int I = 1; I <= n; I ++) {scanf ("% d", &. f, & S);. index = I; q [S]. push (a) ;}printf ("Case # % d: \ n", iCase); for (int I = 0; I <n; I ++) {I Nt fast =-1, id = 1; for (int j = 1; j <= 100; j ++) if (! Q [j]. empty () {Node tmp = q [j]. top (); if (tmp. F + I * j> fast) fast = tmp. F + I * j, id = j; else if (tmp. F + I * j = fast & tmp. index <q [id]. top (). index) id = j;} printf ("% d", q [id]. top (). index); q [id]. pop (); if (I <n-1) printf (""); else printf ("\ n") ;}} return 0 ;}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.