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 ...
随机推荐
- Singleton Pattern(单例模式)
1.简介 单例模式,顾名思义,即在整个系统中,类的实例对象只有一个. 单例模式具有以下特点: 单例类只能有一个实例 单例类必须自己创建自己的唯一实例 单例类必须给所有其他对象提供这一实例 2.实现 其 ...
- maven原理
http://www.cnblogs.com/onlys/archive/2011/01/04/1925466.html 基本原理Maven的基本原理很简单,采用远程仓库和本地仓库以及一个类似buil ...
- hdu 5833 Zhu and 772002 异或方程组高斯消元
ccpc网赛卡住的一道题 蓝书上的原题 但是当时没看过蓝书 今天又找出来看看 其实也不是特别懂 但比以前是了解了一点了 主要还是要想到构造异或方程组 异或方程组的消元只需要xor就好搞了 数学真的是硬 ...
- Python网络编程学习_Day10
一.进程与线程 1.区别 进程:一个程序要运行时所需要的所有资源的集合,进程是资源的集合. 一个进程至少需要一个线程,这个线程称为主线程 一个进程里面可以有多个线程 两个进程之间的数据是完全独立,不能 ...
- Unity灯光详解
Lights will bring personality and flavor to your game. You use lights to illuminate the scenes and o ...
- Java NIO Channel和Buffer
Java NIO Channel和Buffer @author ixenos Channel和Buffer的关系 1.NIO速度的提高来自于所使用的结构更接近于OS执行I/O的方式:通道和缓冲器: 2 ...
- [Q]系统环境改变导致“未注册”的解决方法
据用户反映设置账户开机密码后显示未注册, 具体表现: 1. 重装试用版,重新获取注册申请码,发现注册申请码跟原来没有发生变化. 2. 重新使用原来的授权文件注册,但打开后显示未注册. 3. 发现“** ...
- HDU 1329 Hanoi Tower Troubles Again!(乱搞)
Hanoi Tower Troubles Again! Problem Description People stopped moving discs from peg to peg after th ...
- 通过一个表的id同时查询多个表的数据
'select c.字段名,x.字段名 as 改为新的显示名,x.字段名 from 表名1 b,表名2 c,表名3 x where b.字段id=' . $id . ' and b.`字段id`=c. ...
- 图片翻转(Raw Image)
int TransformImageBuffer(unsigned char* pImageBuffer, int width, int height,unsigned char* targetIma ...