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. 初学github

    在公司一直用的SVN做版本管理,倒也没什么问题.最近想自己在家写点东西,上班的时候又想偷偷地写.代码经常在两个地方同步,很是辛苦.反正写的只是一些用来学习测试的代码,干脆放到github上. 1.登录 ...

  2. LitJson处理Json

    LitJSON是一个.NET平台下处理JSON格式数据的类库,小巧.快速.它的源代码使用C#编写,可以通过任何.Net平台上的语言进行调用,目前最新版本为LitJSON 0.9. 下载地址: http ...

  3. Android OpenGL库加载过程源码分析

    Android系统采用OpenGL绘制3D图形,使用skia来绘制二维图形:OpenGL源码位于: frameworks/native/opengl frameworks/base/opengl 本文 ...

  4. Swift学习之类和结构体的创建

    随着一步步的学习,学习到的新知识越来越多了,不管是新的还是旧的,都禁不住时间的堆积,再熟悉的知识点时间久了都会渐渐的忘记,也许这就是人们生活中一种潜在的惰性吧,看似非常熟悉的东西,等到真正要用的时候, ...

  5. PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法

    1 PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法如下, 依次打开Tools -- Execute Commands -- Run Script,运 ...

  6. BlockingQueue

    BlockingQueue的使用 http://www.cnblogs.com/liuling/p/2013-8-20-01.html BlockingQueue深入分析 http://blog.cs ...

  7. (原)vs2013编译成静态库

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5477664.html 1. 在“属性”-“配置属性”-“常规”-“配置类型”里面设置“静态库(.lib ...

  8. postman接口测试工具3.0版本的坑

    今天用postman接口测试工具3.0版本被坑,找了半天,原来postman这个新版本有个坑啊 下面的get参数,第一行不管你填不填,都是无效的,可能是postman的一个bug吧

  9. discuz x2 个人资料项排序问题解决方法、添加自定义字段、修改栏目名称和介绍

    第一次写文章,希望与人提供方便同时,别误人子弟,自己研究的,大家看不懂只改文件就可以了,如果发现不对的地方请回复或直接通知我,谢谢,本来想在discuz论坛上发的,不懂版规也没时间看版规,怕发错,隔小 ...

  10. 序列化layer创建的弹出表单并ajax提交

    /** *createTime:2015-09-13 *updateTime:2015-09-13 *author:刘俊 *phone:13469119119 *QQ:418873053 **/ va ...