HDU 1896 Stones (优先队列)
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
Author
Source
#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 (优先队列)的更多相关文章
- HDU 1896 Stones --优先队列+搜索
一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...
- HDU 1896 Stones (优先队列)
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- HDU 1896 Stones(优先队列)
还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...
- hdu 1896.Stones 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...
- hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的 ...
- HDU 1896:Stones(优先队列)
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- Stones HDU 1896
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大意: 有n个石头,每个石头有:p 它所在的位置 ,d 它能扔多远 从0 开始,遇到第奇 ...
- hdoj 1896 Stones【优先队列】
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- E - Stones 优先队列
来源1896 Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning an ...
随机推荐
- AngularCSS--关于angularjs动态加载css文件的方法(仅供参考)
AngularCSS CSS on-demand for AngularJS Optimize the presentation layer of your single-page apps by d ...
- Finding Lines
Finding Lines 题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8& ...
- mongodb tip-2
1.or 查询的格式: var condition = {$or:[{field:1},{field:2}]} 2.字符串存储日期也可以用$gt $gte $lt $lte 直接比较 var cond ...
- ManualResetEvent和AutoResetEvent的区别
在讨论这个问题之前,我们先了解这样一种观点,线程之间的通信是通过发信号来进行沟通的.(这不是废话) 先来讨论ManualResetEvent,讨论过程中我会穿插一些AutoResetEvent的内容, ...
- 今天学习的裸板驱动之GPIO实验学习心得
GPIO分成很多组今天学习的这个芯片的GPIO有GPA-GPJ个组.具体可在芯片手册中看到. GPIO有很多寄存器,今天学习的这个芯片,他的寄存器分为以下几种类型: (1)端口控制寄存器 (2)端口数 ...
- 图片翻转(Raw Image)
int TransformImageBuffer(unsigned char* pImageBuffer, int width, int height,unsigned char* targetIma ...
- iOS 最新App提交上架流程及部分问题的解决方案2016.12.21,感谢原博主!!!
内容摘自http://www.cocoachina.com/bbs/3g/read.php?tid=330302,原博特别详细,下面我对部分地方进行了修改,主要是对在打包验证和上传的时候遇到的问题进行 ...
- 项目有叉号, 但是没有代码错误的时候, 是JDK版本的问题
windows---proferences---java--compiler进入项目--properties---java Compiler进入项目--properties---Myeclipse-- ...
- response.setContentType与 request.setCharacterEncoding 区别
1.request.setCharacterEncoding()是设置从request中取得的值或从数据库中取出的值的编码 2.response.setContentType指定 HTTP 响应的编码 ...
- 更新BLUZ
bluez的编译安装依赖好些软件,下面记录下,可能比较简陋. configure: error: GLib >= 2.28 is required解决方法:一般glib会被安装,主要是一些开发文 ...