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 ...
随机推荐
- scala 稀疏向量
http://mocom.xmu.edu.cn/article/show/58481eb2e083c990247075a5/0/1 1. /创建一个标签为1.0(分类中可视为正样本)的稠密向量标注点 ...
- HTML鼠标悬浮显示隐藏 JS方法
CSS样式表: @charset "utf-8"; /* CSS Document */ .a { width:80px; height:40px; top:200px; left ...
- JS 相关
计算高度: var a = document.body.clientHeight/2;console.log(a) window.scrollTo(0, document.body.clientHei ...
- zg项目 应用系统编码原则
一.编码说明: 1.系统编码采用三码为原则,通常两码简称之. 1>.子系统或类型 2>.系统小分类 3>.系统大分类 如 IPMS领域业务群: DA 应用软件发展管理系统 DE公用副 ...
- IntelliJ IDEA SVN
第一步:下载svn的客户端,通俗一点来说就是小乌龟啦!去电脑管理的软件管理里面可以直接下载,方便迅速 下载之后直接安装就好了,但是要注意这里的这个文件也要安装上,默认是不安装的,如果不安装,svn中的 ...
- java 里定义的方法参数 (final String... args)
定义成final是为了防止在方法类里面修改参数,final String... args 为JDK新的特性,为可变长参数.编译的时候被解释为:public DCMException(final Str ...
- Java GC的原理
Java GC(garbage collec,垃圾收集,回收) GC是对JVM中的内存进行标记和回收,Sun公司的JDK用的虚拟机都是HotSpot 对象化的实例是放在heap堆内存中的,这里讲的分代 ...
- Android中注解的使用
如果你是一名安卓开发者,你也一定听过大名鼎鼎的网络请求框架Retrofit.它将网络请求的方式以注解的形式展现,极大的提高了代码的可读性,同时网络请求集中写在一个interface中提高了代码的可维护 ...
- SQLserver和oracle中对应的数据类型
- Visual Event查看页面相关绑定事件
页面相关绑定的事件比较复杂,在不熟悉的情况下很难找到相关逻辑的位置,所以希望借助工具来帮自己理清相关事件的脉络走向. 浏览器 工具 chrome( 58.0.3029.110) Visual Even ...