Stones

Time Limit : 5000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 4   Accepted Submission(s) : 3

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

题意是,路上有一堆石头,每次遇到一个石头,如果是奇数个,就将它扔出pi米远,如果是偶数,

则忽略它,如果同一个位置有多个石头,则扔出轻的(扔出距离近的)。问最后一个石头的位置。

可以使用优先队列进行模拟。

#include<iostream>
#include<queue>
using namespace std;
struct node
{int pi;int di;node(int _di,int _pi):pi(_pi),di(_di){}node(){}friend bool operator <(node a,node b){if(a.di!=b.di)return a.di>b.di;else return a.pi>b.pi;}
};
int main()
{int T,N,i,di,pi;cin>>T;while(T--){int imax=0;priority_queue<node>p;cin>>N;while(N--){cin>>di>>pi;p.push(node(di,pi));}int ran=0;while(p.size()){ran++;node c=p.top();p.pop();if(c.di>imax)imax=c.di;if(ran%2!=0)p.push(node(c.di+c.pi,c.pi));}cout<<imax<<endl;}return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/Thereisnospon/p/4768482.html

HDOJ 1896 Stones相关推荐

  1. HDOJ 1896 Stones 解题报告

    题目分类:优先队列+STL 作者:ACShiryu 做题时间:2011-7-18 Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Lim ...

  2. 自己 编译 linux 内核,自己动手编译Linux内核

    OracleDBA之用户管理 再分享一下Oracle中对用户的管理,以下这些东西是我的麦库上存的当时学Oracle的学习笔记今天拿出来和大家分享一下,转载请注明出处,下面用的Oracle的版本是10g ...

  3. Stones HDU 1896

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大意: 有n个石头,每个石头有:p  它所在的位置 ,d  它能扔多远 从0 开始,遇到第奇 ...

  4. 并查集 HDOJ 1232 畅通工程

    题目传送门 1 /* 2 并查集(Union-Find)裸题 3 并查集三个函数:初始化Init,寻找根节点Find,连通Union 4 考察:连通边数问题 5 */ 6 #include <c ...

  5. UVA 1482 - Playing With Stones(SG打表规律)

    UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...

  6. 【HDOJ 3652】B-number

    [HDOJ 3652]B-number 给一整数n 找<=n的整数中能被13整除且含有13的 数位dp 记忆化! . 一入记忆化深似海. ..再也不想用递推了...发现真的非常好想 仅仅要保证满 ...

  7. 【HDOJ】4343 Interval query

    最大不相交集合的数量. 思路是dp[i][j]表示已经有i个不相交集合下一个不相交集合的最右边界. 离散化后,通过贪心解. 1 /* 4343 */ 2 #include <iostream&g ...

  8. 【HDOJ】4579 Random Walk

    1. 题目描述 一个人沿着一条长度为n个链行走,给出了每秒钟由i到j的概率($i,j \in [1,n]$).求从1开始走到n个时间的期望. 2. 基本思路 显然是个DP.公式推导也相当容易.不妨设$ ...

  9. DFS、栈、双向队列:CF264A- Escape from Stones

    题目: Squirrel Liss liv Escape from Stonesed in a forest peacefully, but unexpected trouble happens. S ...

最新文章

  1. 【转】多线程Core Data
  2. (三)Amazon Lightsail 部署LAMP应用程序之连接到Lightsail数据库
  3. Java中Date及Timestamp时间相关内容【转】
  4. 读书笔记《单核工作法》:2
  5. JVM调优:jdk1.8新生代和老年代的比值是1:2
  6. 红色警报 (25 分)【测试点分析】【两种解法】
  7. code vs1517 求一次函数解析式(数论 纯数学知识)
  8. curl 请求日志_kong api网关日志 将请求和响应数据附加到磁盘上的日志文件中
  9. CVPR2019 | 弱监督图像分类建模
  10. Tomcat源码分析——server.xml文件的加载
  11. Springboot+多线程+等待获取执行结果
  12. 创业始于自信 成功缘于诚信
  13. java action url,Java ViewHandler.getActionURL方法代码示例
  14. 面向对象技术之系统分析:类图
  15. TKT中文编程语言简介
  16. excel表格打印每页都有表头_Excel打印时如何实现每一页纸上都有表头?
  17. Element UI修改message控件显示的时间
  18. 自定义View-波浪动效
  19. 关注李敖神州文化之旅
  20. 解决搜狗输入法ctrl+shift+z 和phpstorm冲突的问题

热门文章

  1. MySQL数据库学习笔记(二)----MySQL数据类型
  2. Wcf Rest Service模板--方法输入输出流数据
  3. 为iptables增加layer7补丁(Linux2.6.25内核
  4. MATLAB学习笔记(十三)
  5. linux中特殊字符反引号,linux中的特殊符号$ ‘’ 反引号 反斜杠
  6. CNSA与CASC和CASIC的区别
  7. Java删除指定值结点[递归]图解
  8. 2-4实战分类之模型构建
  9. 卸载nginx php mysql_centos7中配置nginx+php-fpm+swoole+mysql环境教程
  10. java war目录_java war包 路径--解决war包中文件路径问题