Stones

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

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

因为每次是要取最近的石头扔出去,所以要用到优先队列,又因为只能扔奇数次碰到的石头,那么可以用一个bool型变量的判断来做到。

#include<iostream>
#include<queue>
using namespace std;
struct st{int pos;int jl;bool operator<(const st t)const{if(pos!=t.pos)return t.pos<pos;return t.jl<jl;}
};
int main(){int n;cin>>n;while(n--){int m;cin>>m;priority_queue<st> st1;st st2;int i;for(i=0;i<m;i++){scanf("%d%d",&st2.pos,&st2.jl);st1.push(st2);}bool fl=true;while(!st1.empty()){st2=st1.top();st1.pop();if(fl){fl=false;st2.pos+=st2.jl;st1.push(st2);}else fl=true;}cout<<st2.pos<<endl;}return 0;
}

hdu1896 Stones相关推荐

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

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

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

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

  3. Codeforces 768E:Game of Stones

    Codeforces 768E:Game of Stones 题目链接:http://codeforces.com/contest/768/problem/E 题目大意:给定$n$堆石子,初始每堆$s ...

  4. CodeForces - 1110E-Magic Stones(差分+思维)

    Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is e ...

  5. [ICPC 北京 2017 J题]HihoCoder 1636 Pangu and Stones

    #1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...

  6. Moving stones(暴力+思维)

    链接:https://ac.nowcoder.com/acm/contest/5891/D 来源:牛客网 题目描述 One day, GK was getting very bored with pa ...

  7. HDOJ 1896 Stones 解题报告

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

  8. *【2019牛客暑期多校训练营(第三场)- G】Removing Stones(分治)

    题干: 链接:https://ac.nowcoder.com/acm/contest/883/G 来源:牛客网 Summer vacation is coming and Mark has retur ...

  9. 【CodeForces - 264A】Escape from Stones (模拟,卡精度的处理)

    题干: Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a m ...

最新文章

  1. Android中Parcelable接口用法
  2. 菜鸟网络 | 寄件业务的产品逻辑
  3. Linux服务-Samba文件服务器部署
  4. 转:Java反射教程
  5. unity3d 可视化编程_R编程系列:R中的3D可视化
  6. LeetCode - Easy - 119. Pascal‘s Triangle II
  7. 中小企业上云多地域办公组网,建立高质量云上内网环境
  8. MQTT 消息通信工具使用
  9. 一个完整的软件开发过程到底需要哪些步骤?
  10. PMP项目管理—项目风险管理(7)
  11. Android中 一些维持状态的经验
  12. MySQL取离当前时间最近的记录
  13. 如何将彩色文本打印到终端?
  14. 考研政治与专业课总结(持续更新)
  15. 通俗版:“什么是ERP” -----文章出处:51testing论坛
  16. 【笔记】最后14堂星期二的课
  17. sql位运算符【(位与)、~(位非)、|(位或)、^(位异或)】与位移
  18. 经典的深度强化学习劝退文读后感
  19. XCOM V2.6 串口打印出来中文乱码,字体格式错乱的一种原因(设置没问题,突然乱码)
  20. SharePoint2010安装文档

热门文章

  1. 时序知识图谱的增量构建
  2. Lucene,Solr,Elasticsearch之间的区别和联系
  3. 将一个接口响应时间从2s优化到 200ms以内的一个案例
  4. 【Unity3D插件】uMOBA插件分享《Moba类游戏框架插件》
  5. 【光电工程实训】物理光学 干涉及衍射实验 偏振现象 波的衍射理论 光的偏振 方晶石
  6. 信息孤岛问题有多难?教你一招,免费解决
  7. ROC曲线绘制相关R包下载和安装方式
  8. 服务器域名修改,服务器修改域名
  9. python跑模型是什么意思_django模型是什么意思
  10. 小米Air笔记本以UEFI模式硬盘GPT分区启动Win7_64位系统