Hdu1896 Stones(优先队列) 2017-01-17 13:07 40人阅读 评论(0) 收藏
Stones
Time Limit : 5000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 41 Accepted Submission(s) : 34
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
———————————————————————————————————————————————————————————————————————————
题目说在一条直线道路上有n个石头,往前走,遇到一个数一个,如果遇到的是第奇数个那就把这个石头往前扔距离D[i], 如果是第偶数个,就放置不管。
问遇到的最后一个石头距离出发点的位置是多少。
做起来也比较简单就是每遇到第奇数个石头,就将其加上D[i],放回到优先队列中,然后再去掉一个石头
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; struct node
{
int x, t;
}; struct cmp
{
bool operator () (const node a, const node b)
{
if(a.x != b.x)return a.x > b.x;
else return a.t > b.t;
}
}; int main()
{
int o,n;
priority_queue<node,vector<node>,cmp>q;
node a[100005],k;
scanf("%d",&o);
while(o--)
{
while(!q.empty())
q.pop();
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lld%d",&a[i].x,&a[i].t);
q.push(a[i]);
}
while(!q.empty())
{
k=q.top();
q.pop();
k.x+=k.t;
q.push(k);
q.pop();
}
printf("%d\n",k.x);
}
return 0;
}
Hdu1896 Stones(优先队列) 2017-01-17 13:07 40人阅读 评论(0) 收藏的更多相关文章
- POJ1087 A Plug for UNIX 2017-02-12 13:38 40人阅读 评论(0) 收藏
A Plug for UNIX Description You are in charge of setting up the press room for the inaugural meeting ...
- Dirichlet's Theorem on Arithmetic Progressions 分类: POJ 2015-06-12 21:07 7人阅读 评论(0) 收藏
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- java面试和笔试大全 分类: 面试 2015-07-10 22:07 10人阅读 评论(0) 收藏
2.String是最基本的数据类型吗? 基本数据类型包括byte.int.char.long.float.double.boolean和short. java.lang.String类是final类型 ...
- 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏
在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...
- hdu 1712, multiple-choice knapsack, 分类: hdoj 2015-07-18 13:25 152人阅读 评论(0) 收藏
reference: 6.4 knapsack in Algorithms(算法概论), Sanjoy Dasgupta University of California, San Diego Chr ...
- Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏
Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...
- Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...
- Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Oracle错误IMP-00010: 不是有效的导出文件, 头部验证失败 分类: Oracle 2015-07-09 13:56 20人阅读 评论(0) 收藏
Oracle 11g的dmp备份文件导入到Oracle 10g,出现错误信息: Import: Release 10.2.0.1.0 - Production on 星期四 7月 9 13:47:04 ...
随机推荐
- hibernate 中一对多的注解配置
//一方@Entity@Table(name="test_classinfo")public class ClassInfo { @Id @SequenceGenerator(na ...
- 吴裕雄 数据挖掘与分析案例实战(10)——KNN模型的应用
# 导入第三方包import pandas as pd # 导入数据Knowledge = pd.read_excel(r'F:\\python_Data_analysis_and_mining\\1 ...
- jenkins 自动构建gitlab项目
安装的plugin: - kubernetes:1.7.1 - workflow-aggregator:2.5 - workflow-job:2.21 - credentials-b ...
- git冲突解决方案 Intellij IDEA
一般在团队合作开发一个项目的过程中,经常出现两个人同时修改一个文件然后都向主master提交commit,这样就会产生冲突(conflict),那么这种情况如何解决? 1 新建分支 如果项目的主分支是 ...
- 如何添加ECSHOP广告位置
如何添加ECSHOP广告位置 我们都知道ecshop系统默认的广告位置非常的少,但是一个电子商务网站岂能离开广告?庆幸的是,ecshop预留了足够强大的组件让我们能够完全有可能实现任意我们想要广告位置 ...
- jquery 动态添加的代码不能触发绑定事件
今天发现jQuery对动态添加的元素不触发事件,比如blur.click事件等 参考文章证明了我的结论,并给出了原因及解决方案 原因:程序找不到动态添加的节点. 解决方案:在绑定父元素后的子元素 $( ...
- 25-javaweb接入支付宝支付接口
想熟悉支付宝接口支付,后面可能会用,不如在课设中试试手.好吧听说支付宝不微信支付要简单些,就拿支付宝的先练下手吧. 基本学习流程,百度一下,找篇博客看下. 推荐下面这个篇博客,讲的挺好的,复制过来. ...
- Raft 一致性算法论文译文
本篇博客为著名的 RAFT 一致性算法论文的中文翻译,论文名为<In search of an Understandable Consensus Algorithm (Extended Vers ...
- vue1.0学习
vue 一片html代码配合上json,在new出来vue实例 Demo:1 数据双向绑定(v-model="message",{{message}}) <div id=&q ...
- 02 请求库之 requests模块
requests模块 一 介绍 #介绍:使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) #注意:requ ...