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.

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

OutputJust 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 题意是求从出发点到最后一块石头的距离,遇到奇数石头可以扔,偶数不管,那么就是创建优先队列,扔出去的,按照扔出去以后的位置和原来能扔的距离入队就好了。不停直到队列为空。 代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue> using namespace std; struct stone
{
int loc,dis;
friend bool operator <(stone a,stone b)
{
if(a.loc==b.loc)return a.dis>b.dis;
return a.loc>b.loc;
}
}temp,cn;
int main()
{
int T,n,p,d,loca=,c=,maxi=;
priority_queue <stone>q;
scanf("%d",&T);
while(T--)
{
loca=c=maxi=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&p,&d);
temp.loc=p,temp.dis=d;
q.push(temp);
}
while(!q.empty())
{
c++;
cn=q.top();
q.pop();
if(loca<cn.loc)loca=cn.loc;
if(c%==)
{
temp.loc=loca+cn.dis;
if(maxi<temp.loc)maxi=temp.loc;
temp.dis=cn.dis;
q.push(temp);
}
}
printf("%d\n",maxi>loca?maxi:loca);
}
}

Stones 优先队列的更多相关文章

  1. E - Stones 优先队列

    来源1896 Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning an ...

  2. Hdu1896 Stones(优先队列) 2017-01-17 13:07 40人阅读 评论(0) 收藏

    Stones Time Limit : 5000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submis ...

  3. HDU 1896 Stones (优先队列)

    Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...

  4. HDU 1896 Stones --优先队列+搜索

    一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...

  5. Stones(优先队列)

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

  6. HDU 1896:Stones(优先队列)

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Sub ...

  7. hdoj 1896 Stones【优先队列】

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

  8. HDU 1896 Stones(优先队列)

    还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...

  9. HDU 1896 Stones (优先队列)

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

随机推荐

  1. 如何查看DNS?

    查看dns服务ip:    命令: ipconfig/all  查看dns缓存:    命令:ipconfig/displaydns     强制更新缓存:    命令:ipconfig /flush ...

  2. Python -- Scrapy 命令行工具(command line tools)

    结合scrapy 官方文档,进行学习,并整理了部分自己学习实践的内容 Scrapy是通过 scrapy 命令行工具进行控制的. 这里我们称之为 “Scrapy tool” 以用来和子命令进行区分. 对 ...

  3. 各种容器与服务器的区别与联系 Servlet容器 WEB容器 Java EE容器 应用服务器 WEB服务器 Java EE服务器

    转自:https://blog.csdn.net/tjiyu/article/details/53148174 各种容器与服务器的区别与联系 Servlet容器 WEB容器 Java EE容器 应用服 ...

  4. (GoRails) Form对象设计风格: 用自建的Model来对参数进行操作。

    视频:https://gorails.com/episodes/form-objects-design-pattern?autoplay=1 git代码 :https://github.com/gor ...

  5. 介绍 Jersey 依赖

    Jersey 使用 Apache Maven 进行构造和安装.非快照(Non-snapshot)Jersey 发行版本是不会部署到 中心 Maven 仓库(Central Maven Reposito ...

  6. hdu 2018多校8

    A.Character Encoding 简单计数 m个非负数和等于k的方案数为$\binom{m+k-1}{k}$, 但题目还要求每个数小于n, 容斥一下即可 即$ans = \sum\limits ...

  7. Multi-target tracking by Lagrangian relaxation to min-cost network flow

    Multi-target tracking by Lagrangian relaxation to min-cost network flow high-order constraints min-c ...

  8. python-day30--粘包

    一. 什么是粘包 1.须知:只有TCP有粘包现象,UDP永远不会粘包 2.所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少字节的数据所造成的. 二.两种情况下会发生粘包. 1. ...

  9. POJ 3481 treap

    这是利用treap写的二叉排序树,只要理解其中旋转能够改变树的左右子树平衡度,即高度之差,差不多就能掌握treap树的要领了. 相对于其他高级BST,treap树实现应该算最简单了,利用的是随机树产生 ...

  10. 快照库MV不能成功刷新问题的解决

    前几天,一个用户找到我,说他们的物化视图不能刷新了,这得从几天前主库的一次意外down机说起(另文说明),前几天,用户现场的一个中心库因某原因意外down掉了,当时短期内对中心库进行了重启修复,没有造 ...