HDU 1896 stone
来源:互联网 发布:郑州中学编程培训班 编辑:程序博客网 时间:2024/06/06 04:53
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.
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.
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
221 52 421 56 6
Sample Output
1112#include<iostream>#include<stdio.h>#include<queue>using namespace std;struct node{ int p,d; friend bool operator<(node n1,node n2) { if(n1.p==n2.p) { return n1.d>n2.d; } else return n1.p>n2.p; }};int main(){ int t,i,max,k,n; struct node stone; priority_queue<node>q; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d%d",&stone.p,&stone.d); q.push(stone); } k=0; max=0; while(!q.empty()) { stone=q.top(); q.pop(); k=k+1; if(k&1) { if(stone.p+stone.d>max) { max=stone.p+stone.d; } stone.p=stone.p+stone.d; q.push(stone); } } printf("%d\n",max); }}
0 0
- HDU 1896 stone
- hdu 1896 Stone
- HDU 4038 Stone
- hdu 1729 Stone Game
- Hdu 1729 Stone Game
- hdu 4387 Stone Game
- HDU 4764 Stone
- HDU 4764 Stone
- HDU 4764-Stone(博弈)
- HDU-Lifting the Stone
- HDU 4764 Stone
- hdu 4764 Stone
- HDU 4764 Stone
- HDU 4764 Stone(博弈)
- hdu 4387 Stone Game
- HDU 1729 Stone Game
- hdu 4764 Stone
- HDU 1729 Stone Game
- hdu-2091-空心三角形
- hdu
- 计算机网络笔试面试题目大全
- HDU 4902 Nice boat
- JAVA IO 同步与异步、阻塞与非阻塞
- HDU 1896 stone
- Mplayer 音量控制
- 线性DP 四边形不等式优化 hdu3506
- 使用adb查看数据库的一些命令
- Java IO相关
- 匈牙利算法
- java 格式化当前日期有误
- Unix网络编程之环境搭建
- linux的mmc_spi学习笔记1