Stones

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

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
题意:按照见的第几个石子,第奇数个石子扔,同一位置的石子需按照扔的远近从小到大排序;所以用到优先队列;
代码:
 #include<stdio.h>
#include<queue>
using namespace std;
struct Node{
int position,dis;
friend bool operator < (Node a,Node b){
if(a.position!=b.position)return a.position>b.position;
else return a.dis>b.dis;
}
};
int main(){
int T,N,k;
Node m;
scanf("%d",&T);
while(T--){k=;priority_queue<Node>stone;
scanf("%d",&N);
while(N--)scanf("%d%d",&m.position,&m.dis),stone.push(m);
while(!stone.empty()){k++;
if(k&)m=stone.top(),m.position+=m.dis,stone.push(m);
stone.pop();
if(stone.empty())printf("%d\n",stone.top().position);
}
}
return ;
}

Stones(优先队列)的更多相关文章

  1. E - Stones 优先队列

    来源1896 Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning an ...

  2. Stones 优先队列

    Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk ...

  3. Hdu1896 Stones(优先队列) 2017-01-17 13:07 40人阅读 评论(0) 收藏

    Stones Time Limit : 5000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submis ...

  4. HDU 1896 Stones (优先队列)

    Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...

  5. HDU 1896 Stones --优先队列+搜索

    一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...

  6. HDU 1896:Stones(优先队列)

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Sub ...

  7. hdoj 1896 Stones【优先队列】

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

  8. HDU 1896 Stones(优先队列)

    还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...

  9. HDU 1896 Stones (优先队列)

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

随机推荐

  1. phpcms加载系统类与加载应用类之区别详解

    <?php 1. 加载系统类方法load_sys_class($classname, $path = ''", $initialize = 1)系统类文件所在的文件路径:/phpcms ...

  2. Java单元测试:@BeforeClass,@Before,@Test,@After,@AfterClass中的问题详解

    在Junit4中还有的测试注解有:  @BeforeClass ,@Before,@Test,@After,@AfterClass 1.其中:@BeforeClass,@AfterClass是Juni ...

  3. C# CheckedListBox控件的使用方法

    1. 加入项 checkedListBox1.Items.Add("蓝色"); checkedListBox1.Items.Add("红色"); checked ...

  4. Weblogic的Admin server进程将CPU消耗尽问题解决

    1.serverCPU被耗尽,持续100% 以下附nmon图 2.两个weblogicadmin server进程将CPU耗尽 问题:24298进程,占用百分之四千多的CPU资源 23529进程,占用 ...

  5. [Immutable.js] Differences between the Immutable.js Map() and List()

    The Immutable.js Map() is analogous to a Javascript Object or Hash since it is comprised of key-valu ...

  6. [Protractor] Use protractor to catch errors in the console

    For any reason, there is an error in your code, maybe something like undefined error. Protractor sti ...

  7. 同一个页面多个CALayer重绘的办法

    //知识点,CALayer的重绘,-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx 方法,CALayer的渐变色.多个CALa ...

  8. github使用-知乎的某小姐的一篇文章

    作者:珊姗是个小太阳链接:http://www.zhihu.com/question/20070065/answer/79557687来源:知乎著作权归作者所有,转载请联系作者获得授权. 作为一个文科 ...

  9. 一个简单方法:构造xml的document,并将其转换为string

    首先,构造一个document对象: Document doc = null; try { doc = DocumentBuilderFactory.newInstance() .newDocumen ...

  10. MRC BlOCK ARC

       /*-------------------MRC环境中-------------------------*/     //使用局部变量:a到block块中,为了在block中能够使用这个变量,将 ...