hdu1896 Stones
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
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
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
Sample Input
2 2 1 5 2 4 2 1 5 6 6
Sample Output
11
12
因为每次是要取最近的石头扔出去,所以要用到优先队列,又因为只能扔奇数次碰到的石头,那么可以用一个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;
}
hdu1896 Stones相关推荐
- UVA 1482 - Playing With Stones(SG打表规律)
UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...
- DFS、栈、双向队列:CF264A- Escape from Stones
题目: Squirrel Liss liv Escape from Stonesed in a forest peacefully, but unexpected trouble happens. S ...
- Codeforces 768E:Game of Stones
Codeforces 768E:Game of Stones 题目链接:http://codeforces.com/contest/768/problem/E 题目大意:给定$n$堆石子,初始每堆$s ...
- CodeForces - 1110E-Magic Stones(差分+思维)
Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is e ...
- [ICPC 北京 2017 J题]HihoCoder 1636 Pangu and Stones
#1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...
- Moving stones(暴力+思维)
链接:https://ac.nowcoder.com/acm/contest/5891/D 来源:牛客网 题目描述 One day, GK was getting very bored with pa ...
- HDOJ 1896 Stones 解题报告
题目分类:优先队列+STL 作者:ACShiryu 做题时间:2011-7-18 Stones Time Limit: 5000/3000 MS (Java/Others) Memory Lim ...
- *【2019牛客暑期多校训练营(第三场)- G】Removing Stones(分治)
题干: 链接:https://ac.nowcoder.com/acm/contest/883/G 来源:牛客网 Summer vacation is coming and Mark has retur ...
- 【CodeForces - 264A】Escape from Stones (模拟,卡精度的处理)
题干: Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a m ...
最新文章
- Android中Parcelable接口用法
- 菜鸟网络 | 寄件业务的产品逻辑
- Linux服务-Samba文件服务器部署
- 转:Java反射教程
- unity3d 可视化编程_R编程系列:R中的3D可视化
- LeetCode - Easy - 119. Pascal‘s Triangle II
- 中小企业上云多地域办公组网,建立高质量云上内网环境
- MQTT 消息通信工具使用
- 一个完整的软件开发过程到底需要哪些步骤?
- PMP项目管理—项目风险管理(7)
- Android中 一些维持状态的经验
- MySQL取离当前时间最近的记录
- 如何将彩色文本打印到终端?
- 考研政治与专业课总结(持续更新)
- 通俗版:“什么是ERP” -----文章出处:51testing论坛
- 【笔记】最后14堂星期二的课
- sql位运算符【(位与)、~(位非)、|(位或)、^(位异或)】与位移
- 经典的深度强化学习劝退文读后感
- XCOM V2.6 串口打印出来中文乱码,字体格式错乱的一种原因(设置没问题,突然乱码)
- SharePoint2010安装文档