http://acm.hdu.edu.cn/showproblem.php?pid=1896

题意:一个人从0开始走起,遇到偶数个石头就踢。要是同一位置有多个石头,则先扔最重的石头(也就是扔的最近的那个石头),要你求扔的石头离初始位置的最大距离。

Stones

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1231    Accepted Submission(s):
759

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
 
 
Author
Sempr|CrazyBird|hust07p43
 
Source
 
Recommend
lcy   |   We have carefully selected several similar
problems for you:  1892 1899 1895 1894 1897 
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct node
{
friend bool operator<(node n1,node n2)
{ if(n1.p>n2.p)//小的优先级大。
return ;
else
{
if(n1.p==n2.p&&n1.d>n2.d)
{
return ;
}
else
return ;
} }
int p;
int d;
};
int main()
{
int t,f;
scanf("%d",&t);
while(t--)
{
int n,i;
scanf("%d",&n);
struct node a;
priority_queue<node>q;
for(i=;i<n;i++)
{
scanf("%d%d",&a.p,&a.d);
q.push(a);
}
int s=;
int ans=;
while(!q.empty())
{
s++;
a=q.top();
// printf("p1=%d,d1=%d\n",a.p,a.d);
q.pop();
if(s%==)
{
// printf("p=%d,d=%d\n",a.p,a.d);
// ans+=a.p+a.d;
a.p=a.p+a.d;
// f=a.d;
q.push(a);
} } printf("%d\n",a.p);
}
return ;
}

HDU-1896 Stones的更多相关文章

  1. hdu 1896.Stones 解题报告

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

  2. HDU 1896 Stones (优先队列)

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

  3. HDU 1896 Stones (优先队列)

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

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

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

  5. HDU 1896 Stones(优先队列)

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

  6. Stones HDU 1896

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

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

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

  8. hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)

    http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的 ...

  9. hdoj 1896 Stones【优先队列】

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

  10. HDU 1896 【留个使用priority_queue容器的样例】

    感谢<啊哈!算法>的讲解,水鸟弄懂了什么是优先队列. 题意是:在路上有很多石子,给出他们的初始位置和小明能够将他们扔出的距离,当小明遇到奇数个石子的时候就会把它扔出,遇到偶数个就会忽略他, ...

随机推荐

  1. Web前端新人之CSS样式选择器

    最近在学习css样式.那么我就想先整理一下css样式的选择器 规则结构: 每个规则都有两个基本部分:选择器和声明块.声明块由一个或者多个声明组成,每个声明则是一个属性—值对(property-valu ...

  2. jQuery.hhLRSlider 左右滚动图片插件

    /**  * jQuery.hhLRSlider 左右滚动图片插件  * User: huanhuan  * QQ: 651471385  * Email: th.wanghuan@gmail.com ...

  3. tar解压去除文件夹

    tar zxvf test.tar.gz  --strip-components 1 解压到当前目录,并去除一级目录

  4. m2e插件的新下载地址

    今天在按照<Maven实战>这本书给eclipse配置maven的m2eclipse插件的时候发现,书中写的老的下载地址http://m2eclipse.sonatype.org/site ...

  5. Python设计模式——模版方法模式

    1.模版方法模式 做题的列子: 需求:有两个学生,要回答问题,写出自己的答案 #encoding=utf-8 __author__ = 'kevinlu1010@qq.com' class Stude ...

  6. centos 卸载vsftpd方法

    centos 卸载vsftpd方法 在服务器上安装了vsftpd,配置出错需要卸载vsftpd.卸载vsftpd的命令如下: 1 [root@localhost ~]# rpm -aq vsftpd2 ...

  7. 云告警平台 OneAlert :如何帮助运维工程师做好汇报?

    OneAlert 是北京蓝海讯通科技有限公司旗下产品,中国首个 SaaS 模式的云告警平台,可集成 Zabbix ,Nagios ,Solarwinds ,AWS CloudWatch ,阿里云 ,监 ...

  8. Hibernate 一对多自身双向关联关系 用于类别表的实现

    分类:一对多自身双向关联关系 Java持久化类: package com.hyy.hibernate.one_to_many.domain; import java.util.HashSet; imp ...

  9. 李洪强iOS开发之-PCH文件的配置

    pch 可以用来存储共享信息,比如设备屏幕的宽度,高度.版本号等等 公用信息 Xcode 老版本会自动为我们创建pch文件,新版本开始不自动创建了,如果需要使用可以自己手动创建 创建完成后可以在里面定 ...

  10. 《ArcGIS Engine+C#实例开发教程》第七讲 图层符号选择器的实现2

    原文:<ArcGIS Engine+C#实例开发教程>第七讲 图层符号选择器的实现2 摘要:在第七讲 图层符号选择器的实现的第一阶段中,我们完成了符号选择器窗体的创建与调用.在第二阶段中, ...