HDU 1896-Stones

来源:互联网 发布:qq刷钱软件 编辑:程序博客网 时间:2024/05/22 01:34

Stones

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3111    Accepted Submission(s): 2027


题目链接:点击打开链接


Problem Description
Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time. 
There are many stones on the road, when he meet a stone, he will throw it ahead as far as possible if it is the odd stone he meet, or leave it where it was if it is the even stone. Now give you some informations about the stones on the road, you are to tell me the distance from the start point to the farthest stone after Sempr walk by. Please pay attention that if two or more stones stay at the same position, you will meet the larger one(the one with the smallest Di, as described in the Input) first. 
 

Input
In the first line, there is an Integer T(1<=T<=10), which means the test cases in the input file. Then followed by T test cases. 
For each test case, I will give you an Integer N(0<N<=100,000) in the first line, which means the number of stones on the road. Then followed by N lines and there are two integers Pi(0<=Pi<=100,000) and Di(0<=Di<=1,000) in the line, which means the position of the i-th stone and how far Sempr can throw it.
 

Output
Just output one line for one test case, as described in the Description.

Sample Input
2
2
1 5
2 4
2
1 5
6 6
 


Sample Output
11
12



题意:
有个人的车坏了,他做了个游戏,扔石子,给出石子的 数量以及每个石子离原点的距离和它能扔出的距离,这个人从原点出发,遇见第奇数个石子就扔,遇见第偶数个就不扔,往前走,让求扔完最后一个石子的距离到远点的距离是多少。


分析:
在这里我特别说两点,第一是当在某一点遇见一堆石子的时候,要选择扔的最近的石子扔 (题意上说的,这也是我在做题时没认真读题意所困住的点),第二,我们来看第一组测试数据,有 2 个石子,A石子离原点的距离为 1 ,能扔出的距离为 5 ,B石子到原点的距离为 2 ,能扔出的距离为 4,这个人从原点出发,第先遇见A石子,然后扔出,所以现在 A 石子离原点的距离为 6 ,能扔出的距离仍然是 5 ,第二个遇见的是B石子,不扔,再向前走,第三次又遇见了 A 石子,于是再扔,这时 A 石子离原点的距离为 11 ,再向前,第四次遇见的仍然是 A 石子,不扔,然后前面就没有石子了,所以答案是 11.





#include <iostream>#include <stdio.h>#include <queue>using namespace std;struct book{    int pi,di;}s;bool operator < (const book &a,const book &b){    if(a.pi==b.pi)        return a.di > b.di;    else        return a.pi > b.pi;}int main(){    int t,n,m,k,l;    scanf("%d",&t);    while(t--)    {        priority_queue <book> q;        scanf("%d",&l);        while(l--)        {            scanf("%d %d",&m,&n);            s.pi=m;            s.di=n;            q.push(s);        }        k=1;        while(!q.empty())        {            s=q.top();            q.pop();            if(k%2==1)            {                s.pi+=s.di;                q.push(s);            }            k++;        }        printf("%d\n",s.pi);    }    return 0;}


 

原创粉丝点击