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

Author

Sempr|CrazyBird|hust07p43

Source

HDU 2008-4 Programming Contest
 #include<iostream>
#include<queue>
using namespace std;
struct node//石头
{
int pos,dis;//pos表示位置,dis表示距离
};
struct cmp//queue的比较函数
{
bool operator()(node a,node b)
{
if(a.pos==b.pos)return a.dis>b.dis;
return a.pos>b.pos;//top是最小
}
};
int n,num;//n表示石头的个数,num表示遇到的石头序号
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n;
priority_queue<node,vector<node>,cmp>Q;
node stone;
for(int i=;i<n;i++)
{
cin>>stone.pos>>stone.dis;
Q.push(stone);
}
num=;
while(!Q.empty())//没有可投掷的石头时,一直pop top
{
stone=Q.top();
Q.pop();
num++;
if(num%==)
{
stone.pos+=stone.dis;
Q.push(stone);
}
}
cout<<stone.pos<<endl;
}
return ;
}

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

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

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

  2. HDU 1896 Stones (优先队列)

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

  3. HDU 1896 Stones(优先队列)

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

  4. hdu 1896.Stones 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...

  5. hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)

    http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的 ...

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

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

  7. Stones HDU 1896

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大意: 有n个石头,每个石头有:p  它所在的位置 ,d  它能扔多远 从0 开始,遇到第奇 ...

  8. hdoj 1896 Stones【优先队列】

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

  9. E - Stones 优先队列

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

随机推荐

  1. CSS控制文本在一行内显示,若有多余字符则使用省略号表示

    强制文本在一行内显示,多余字符使用省略号 text-overflow: ellipsis; overflow: hidden; white-space: nowrap;

  2. curl命令PostJson

    curl -H "Content-Type: application/json" -X POST  --data '{"data":"1"} ...

  3. 深入.NET平台和C#编程

    第一章  深入.NET框架 1.Microsoft.NET框架概述: 1).NET介绍 2)为什么需要.NET框架 通过如下两个问题说明为什么需要.NET框架 01,C#程序可以再不同平台(PDA,P ...

  4. iOS杂货

    iOS 导航栏TitleView居中的问题 titleVIew 默认情况下 是居中显示的,出现不居中的情况原因有两个:1,leftBarButtonItem,和rightBarButtonItem 留 ...

  5. 关于php数组是否要声明

    不知道大家有没有这样玩过php数组,正常情况下直接不声明,直接使用数组,会发现输出的与声明后的结果是一样的.

  6. ORACLE AWR性能报告和ASH性能报告的解读

    数据库的性能分析可分为会话级和系统级:如果确定某个会话存在性能问题,最常见的分析方式是对这个会话做一个SQL_TRACE或者10046事件,通过分析trace文件来定位问题所在.如果无法确定哪个会话性 ...

  7. CodeForces 710B Optimal Point on a Line

    递推. 先对$a[i]$进行从小到大排序. 然后计算出每个点左边所有点到这个点的距离之和$L[i]$,以及右边每个点到这个点的距离之和$R[i]$. 这两个都可以递推得到. $L\left[ i \r ...

  8. USACO 3.2 Contact

    ContactIOI'98 The cows have developed a new interest in scanning the universe outside their farm wit ...

  9. .Net 生成二维码【超简易,仅供学习】

    1,首先下载DotNetBarcode.dll文件 下载地址: http://dl.downyi.com/dotnetbarcode_dll.rar 2,调用方式 string path = @&qu ...

  10. 使用sublime text3 连接sftp/ftp(远程服务器)

    首先说明的是Sumblime Text 3,下载安装后,打开软件 在红色箭头指定的控制区域粘贴下面这段英文 import urllib.request,os,hashlib; h = '2915d18 ...