hdu1896 Stones
来源:互联网 发布:华南理工网络教育文凭 编辑:程序博客网 时间:2024/06/05 14:07
Stones
Time Limit : 5000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 51 Accepted Submission(s) : 41
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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
因为每次是要取最近的石头扔出去,所以要用到优先队列,又因为只能扔奇数次碰到的石头,那么可以用一个bool型变量的判断来做到。
#include<iostream>#include<queue>using namespace std;struct st{ int pos; int jl; bool operator<(const st t)const { if(pos!=t.pos)return t.pos<pos; return t.jl<jl; }};int main(){ int n; cin>>n; while(n--) { int m; cin>>m; priority_queue<st> st1; st st2; int i; for(i=0;i<m;i++) { scanf("%d%d",&st2.pos,&st2.jl); st1.push(st2); } bool fl=true; while(!st1.empty()){ st2=st1.top(); st1.pop(); if(fl) { fl=false; st2.pos+=st2.jl; st1.push(st2); } else fl=true; } cout<<st2.pos<<endl; } return 0;}
阅读全文
0 0
- HDU1896- Stones
- HDU1896-Stones
- hdu1896 Stones
- Hdu1896 Stones(优先队列)
- Stones(hdu1896)优先队列
- hdu1896 Stones 优先队列使用
- HDU1896 Stones【模拟+优先队列】
- hdu1896 Stones(优先队列水)
- CSU-ACM2017暑期训练1-Debug与STL hdu1896-Stones
- hdu1896
- Stones
- Stones
- Stones
- Stones
- Stones
- HDU1896-priority_queue
- HDU1896(队列应用)
- hdu1896(模拟+优先级队列)
- 数据库读写分离
- hdu 1180 诡异的楼梯
- CentOS Linux服务器安全设置
- 湖南省第九届大学生计算机程序设计竞赛 高桥和低桥
- for循环的基本例子
- hdu1896 Stones
- [leetcode]628. Maximum Product of Three Numbers
- [bzoj4326]NOIP2015 运输计划
- hdu1372 Knight Moves
- HTTP方法_GET 对比 POST
- Service的应用
- 不需要公共JRE???Applet???
- 代码块 继承
- 经典问题的算法与实现