Stones

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

Total Submission(s): 1375    Accepted Submission(s): 859

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
 
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
struct Stone/*存放石头的坐标和扔的距离*/
{
int x;
int y;
};
bool operator< (Stone a,Stone b)/*队列排序,如果坐标相同则按照扔的距离排序*/
{
if(a.x==b.x&&a.y>b.y)
return true;
else return a.x>b.x;
}
int main()
{
int t,n;
scanf("%d",&n);
while(n--)
{
scanf("%d",&t);
Stone temp;
int sum=1;/*用sum来表示第几个要扔的石头*/
priority_queue<Stone>q;/*定义一个队列*/
for(int i=0;i<t;i++)
{
scanf("%d%d",&temp.x,&temp.y);
q.push(temp);/*将每个数据存放到队列中去*/
}
while(!q.empty())/*队列不为空时就一直进行下去*/
{
temp=q.top();/*用temp来表示队顶元素,同时要出队*/
q.pop();
if(sum%2)/*第奇数个要扔的石头才能进入*/
{
temp.x+=temp.y;/*记录石头的位置*/
q.push(temp);
}
sum++;
}
printf("%d\n",temp.x);
}
return 0;
}

hdoj-1896 stones的更多相关文章

  1. hdoj 1896 Stones【优先队列】

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

  2. hdu 1896.Stones 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...

  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 (优先队列)

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

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

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

  6. HDU 1896 Stones(优先队列)

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

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

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

  8. Stones HDU 1896

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

  9. HDU-1896 Stones

    http://acm.hdu.edu.cn/showproblem.php?pid=1896 题意:一个人从0开始走起,遇到偶数个石头就踢.要是同一位置有多个石头,则先扔最重的石头(也就是扔的最近的那 ...

  10. E - Stones 优先队列

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

随机推荐

  1. jsp 文件下载

    有的时候一个模板的下载,这种简单的下载服务端已存在文件功能,就可以方便的通过jsp文件下载的方式来轻松实现. //jsp 页面 js /** * 导出角色 */ function exportRole ...

  2. 重绘DataGridView标头

    最近突然想在DataGridView标头放置一个CheckBox,我就想着重写下DataGridViewColumnHeaderCell抱着试试的心态结果真的是可以的下面是源码:(如果有看不懂的可以加 ...

  3. 2016.01.22 前端学习 HTML/CSS

    学习HTML/CSS  http://edu.51cto.com/course/course_id-3116.html 明日实践

  4. mysql_基础1

    初学mysql,感觉挺有意思的. mysql指令的一些参数: promrt修改提示符:   PROMPT \D mysql的语法规范: 一些函数: 创建数据库: SHOW CREATE DATABAS ...

  5. 解决hash冲突的三个方法-考虑获取

    哈希表值的获取要考虑全部可能空间. 在链地址法中,可能空间就是具有相同hash值的链表.   目录 开放定址法 线性探测再散列 二次探测再散列 伪随机探测再散列 再哈希法 链地址法 建立公共溢出区 优 ...

  6. 5.21leetcode练习

    目录 两数之和 题目 答案 整数反转 题目 思路及答案 回文数 题目 思路及答案 希望每天进步一点点 两数之和 题目 新手司机上路,光荣翻车,没想出来.借了别人的答案,自行领会 答案 整数反转 题目 ...

  7. NBXplorer的配置

    首先,必须安装bitcoin core bitcoin core启动时,会提示你定义数据存放目录,在数据存放目录下,找到bitcoin.conf文件,并填写内容: server=1rpcuser=rp ...

  8. 模态框(layer)

    推荐一个好看的模态框(layer)   地址:http://layer.layui.com/ 相应列子及配置  全部来自于官网,可直接访问官网学习了解. //信息框-例1 layer.alert('见 ...

  9. 《啊哈算法》中P81解救小哈

    题目描述 首先我们用一个二维数组来存储这个迷宫,刚开始的时候,小哼处于迷宫的入口处(1,1),小哈在(p,q).其实这道题的的本质就在于找从(1,1)到(p,q)的最短路径. 此时摆在小哼面前的路有两 ...

  10. C#学习笔记_09_构造方法/函数

    09_构造方法/函数 代码案例 作用:构造函数主要是用来创建对象时为对象赋初值来初始化对象:总与new运算符一起使用在创建对象的语句中,例如A a=new A(); 特点: 构造函数具有和类一样的名称 ...