STl-Throw nails

Source

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

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
using namespace std;
struct Node
{
   int val,id;
   operator <(const  Node &that)const{
   return (val<that.val)||((val==that.val)&&(id>that.id));
   }
};

int main()
{
    int n;
    scanf("%d",&n);
    priority_queue<Node> myqueue[120];
    for(int z=1;z<=n;z++)
    {

        int N;
        scanf("%d",&N);
        for(int i=1;i<=N;i++)
        {
            Node temp;
            int v,d;
            scanf("%d%d",&v,&d);
            temp.val=v;
            temp.id=i;
            myqueue[d].push(temp);

        }
        printf("Case #%d:\n",z);
        for(int i=0;i<N;i++)
        {
            int maxval=-1,index=1<<28,hang;
            for(int k=1;k<120;k++)
            {
                if(!myqueue[k].empty())
                {
                    Node temp=myqueue[k].top();
                    if((i*k+temp.val>maxval)||
                        ((i*k+temp.val==maxval)&&(index>temp.id)))
                    {
                        maxval=i*k+temp.val;
                        index=temp.id;
                        hang=k;
                    }
                }
            }
            if(i==N-1) printf("%d",index);
            else printf("%d ",index);
            myqueue[hang].pop();

        }
        printf("\n");
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容