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. PRD学习笔记:一些需要注意的说明

    控件说明 1)输入框 若输入框有默认提示,点击输入框,弹出软键盘. 当输入框内不为空(空格除外)时,默认显示消失. 2)软键盘的弹出及退去机制 当输入框内必须输入的为数字时,弹出数字软键盘.其余时候, ...

  2. springmvc中返回页面,只在iframe中跳转,而不是整个页面,解决方法。

    问题描述:在我写的主页面中用到了iframe,其中在iframe中有一个button点击提交,然后在Controller中返回页面的时候,是在iframe中打开的,而不是整个页面. 最开始我想用aja ...

  3. Noip 2016

    Day1 思路: 大致是 把一个环拆成链, 找某个人无非是向右找或向左找(即对当前点加或减) 若加上要移动的位置后坐标大于总人数, 就把当前坐标减去总人数, 若减去要移动的位置后坐标小于0, 就把当前 ...

  4. 文档在线预览开源实现方案一:OpenOffice + SwfTools + FlexPaper

    在文档在线预览方面,项目组之前使用的是Microsoft office web apps, 由于该方案需要按照微软License付费,项目经理要我预研一个文档在线预览的开源实现方案.仔细钻入该需求发现 ...

  5. CoreJavaE10V1P3.3 第3章 Java的基本编程结构-3.3 数据类型

    3.3 数据类型 这里所说的数据类型是指 Java的8中基本数据类型,是原生就存在的. 不同进制数的字面值表示方法 进制 字面值表示方法 例子 是否默认 JDK版本支持 2进制 0b或0B前缀(每4位 ...

  6. 随机love'...

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. android工具类常用方法

    1.获取手机唯一识别号 添加AndroidManifest.xml权限 <uses-permission android:name="android.permission.READ_P ...

  8. LanSoEditor_advance1.8.0 视频编辑的高级版本

    ------------------------------------------2017年1月11日11:18:33------------------------------------- 我们 ...

  9. 《Javascript权威指南》

    <Javascript权威指南> chorme.safari中的input或textarea html超链接(a)详细讲解 html5新增及删除标签 html表格 图片加alt属性

  10. 学习smail注入遇到的坑

    1.将需要被反编译的apk包解开之后,找到MainActivity,然后在OnCreate中添加需要加入注入的smail代码: Java代码: /** * 获取Android id * * @para ...