hdu 1896 Stones 优先队列
来源:互联网 发布:淘宝店怎么入驻天猫 编辑:程序博客网 时间:2024/05/21 19:32
Stones
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.
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<stdio.h>#include<string.h>#include<queue>#include<algorithm>using namespace std;struct node{ int x; int dis; friend bool operator <(node a, node b) { if(a.x==b.x) return a.dis>b.dis; return a.x>b.x; }};int main(){ // freopen("in.txt","r",stdin); int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); priority_queue<node>que; node a; for(int i=0;i<n;i++) { scanf("%d%d",&a.x,&a.dis); que.push(a); } int ans=0; int ti=1; while(que.size()) { if(ti%2==0) que.pop(); else { node tp=que.top(); que.pop(); if(ans<tp.x) ans+=(tp.x-ans); tp.x+=tp.dis; if(que.size()==0) ans+=tp.dis; else que.push(tp); } ti++; } printf("%d\n",ans); } return 0;}
0 0
- HDU 1896 Stones(优先队列)
- hdu 1896 Stones 优先队列
- hdu 1896 Stones(优先队列)
- HDU 1896 Stones (优先队列)
- HDU 1896 Stones 【优先队列】
- HDU 1896 Stones(优先队列)
- HDU 1896 Stones 优先队列
- HDU 1896 Stones 优先队列
- HDU 1896 Stones --优先队列+搜索
- HDU 1896 -- Stones (优先队列)
- hdu 杭电1896 Stones【优先队列】
- HDU 1896 Stones(优先队列)
- 【HDU]-1896-Stones(优先队列,好)
- HDU:1896 Stones(优先队列)
- HDU 1896 Stones (优先队列)
- hdu 1896 Stones(优先队列 Dijkstr)
- hdu--1896Stones(优先队列)
- HDU 1896:Stones(优先队列)
- javascript 方括号
- PHP,在Mac上轻松搭建开发环境,基于BitNami MAMP Stack
- Linux系统关闭笔记本触摸板的方法
- 游戏服务器之服务器之间的主动连接
- 如何解决PHP中文乱码问题?php乱码的根绝方案
- hdu 1896 Stones 优先队列
- J2EE分层关于vo和po
- 在Xcode中搭建OpenCV开发环境
- 为什么SEO效果不明显
- android项目之系统信息查看软件
- 关于UML建模工具Architexa的介绍
- getchar()和EOF总结
- tomcat部署成后台运行的服务
- Android源代码编译命令m/mm/mmm/make分析