刷題總結——Throw nails(hdu4393)

題目:

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

 

題目:

  這道題其實有一個很nb的作法··這裏就不提了··網上都有··php

  首先想到這道題因爲嚴格按淘汰順序輸出確定要模擬淘汰的過程···但確定不會是純模擬···ios

  看到SF偏小,而後由每次淘汰最大咱們考慮消除FS中的某個影響··從而利用單調性快速求出最大值··ide

  是否是和NOIP2016蚯蚓很像?this

  咱們將S(由於S<=100)相等的車子塞進同一個有限隊列中··按第一關鍵字F,第二關鍵字標號排序,而後每次模擬時比較每一個隊列的對首元素便可····spa

代碼:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cctype>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
inline int R(){
    char c;int f=0;
    for(c=getchar();c<'0'||c>'9';c=getchar());
    for(;c<='9'&&c>='0';c=getchar())    f=(f<<3)+(f<<1)+c-'0';
    return f;
}
priority_queue<    pair<int,int> >    que[105];
int T,n;
int main()
{
    //freopen("a.in","r",stdin);
    T=R();
    for(int a=1;a<=T;a++)
    {
        printf("Case #%d:\n",a);
        n=R();int f,s,lim=0;
        for(int i=1;i<=n;i++)    f=R(),s=R(),lim=max(lim,s),que[s].push(make_pair(f,-i));
        for(int t=0;t<n;t++){
            int ans,maxx=-1,v;
            for(int i=1;i<=lim;i++){
                if(que[i].empty())    continue;
                int f=que[i].top().first,id=-que[i].top().second;
                if(f+i*t>maxx||(f+i*t==maxx&&id<ans)){
                    maxx=f+i*t;ans=id,v=i;
                }
            }
            if(t!=n-1) printf("%d ",ans);
            else printf("%d",ans);
            que[v].pop();
        }    
        putchar('\n');
    }
    return 0;
}
相關文章
相關標籤/搜索