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

Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time. 

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

In the first line, there is an Integer T(1<=T<=10), which means the test cases in the input file. Then followed by T test cases. 

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

Just output one line for one test case, as described in the Description.

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) 收藏的更多相关文章

  1. 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 ...

  2. 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 ...

  3. java面试和笔试大全 分类: 面试 2015-07-10 22:07 10人阅读 评论(0) 收藏

    2.String是最基本的数据类型吗? 基本数据类型包括byte.int.char.long.float.double.boolean和short. java.lang.String类是final类型 ...

  4. 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏

    在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...

  5. 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 ...

  6. Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏

    Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...

  7. Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏

    Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...

  8. 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) ...

  9. 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 ...

随机推荐

  1. winform程序开机启动时的运行目录

    并不是程序的当前路径,而是系统的某个目录 如环境是win10 64位,路径是 c:\winfows\SysWOW64\ConfigInfor.json

  2. Fiddler 捕获 nodejs 模拟的http请求

    1.设置Fiddler Tools->Options-> Connections Allow remote computers to connect: 2.nodejs 请求有多种 2.1 ...

  3. 在java中使用ffmpeg将amr格式的语音转为mp3格式

    ffmpeg是一个非常强大的音视频处理工具,官网是:http://ffmpeg.org/. 由于ffmpeg在windows上和linux系统上的执行文件不一样(Windows上不需要安装ffmpeg ...

  4. sqlserver2008debug存储过程

    新建一个查询窗口,exec proc_name params…… 然后启动调试 右侧可以选择“逐过程”“逐语句”“跳出”,下方展示变量的值 参考文章:https://www.cnblogs.com/s ...

  5. AndroidStudio 导包遇到so文件的解决方案----------JPush推送

    最近遇到 Couldn't load jpush175 from loader dalvik.system.PathClassLoader 这样一个问题 它说的是AS不能找到库文件 发生在于像Ecli ...

  6. AasyncTask中执行execute()还是executeOnExecutor()

    executeOnExecutor()api 11 才出现的 并行的 效率比execute()高因为execute()是串行的 import android.app.Activity; import ...

  7. mysql5.5以上开启慢查询

    在my.ini配置文件中添加: [mysqld] #开启慢查询 slow_query_log = on #慢查询时间 long_query_time = 0.5 #记录没有使用索引的查询 log_qu ...

  8. PAT 1020 月饼 (25)(精简版代码+思路+推荐测试用例)

    1020 月饼 (25)(25 分)提问 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼.现给定所有种类月饼的库存量.总售价.以及市场的最大需求量,请你计算可以获得的最大收益是 ...

  9. 什么是RNA-Seq (RNA Sequencing)

    什么是RNA-Seq (RNA Sequencing) 2011-07-14 ~ ADMIN 随着ome为词尾的各种组学的出现,转录组学已经成为了人们了解生物信息的一个重要组成部分.人们使用了许多办法 ...

  10. Cookis与文件缓存的区别

    我是一位顶尖的网络专家.稍后更新...