HDU-1896 Stones
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
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.
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.
the Description.
#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的更多相关文章
- hdu 1896.Stones 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...
- HDU 1896 Stones (优先队列)
Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...
- HDU 1896 Stones (优先队列)
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- HDU 1896 Stones --优先队列+搜索
一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...
- HDU 1896 Stones(优先队列)
还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...
- Stones HDU 1896
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大意: 有n个石头,每个石头有:p 它所在的位置 ,d 它能扔多远 从0 开始,遇到第奇 ...
- HDU 1896:Stones(优先队列)
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的 ...
- hdoj 1896 Stones【优先队列】
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- HDU 1896 【留个使用priority_queue容器的样例】
感谢<啊哈!算法>的讲解,水鸟弄懂了什么是优先队列. 题意是:在路上有很多石子,给出他们的初始位置和小明能够将他们扔出的距离,当小明遇到奇数个石子的时候就会把它扔出,遇到偶数个就会忽略他, ...
随机推荐
- .NET高端职位招聘要求
系统架构师: 1.硕士及以上学历,博士有项目成果者优先: 2.五年以上工作经验,三年以上互联网经验,一年以上大型软件项目总体设计.分析.架构经验,有移动互联网或云计算虚拟化系统设计开发经验者优先: 3 ...
- yii2 model常用验证规则
//字段必填[['username'],'required','message'=>'{attribute}不能为空!'][['username','password'], 'required' ...
- Linux下为PHP安装oci8及pdo_oci扩展
下载instantclient 以及sdk instantclient-basic-linux-x86-64-11.2.0.2.0.zip oracle-instantclient11.2-sdk-1 ...
- 用最直白的语言告诉你,hadoop是什么?
hadoop应历史之潮流,随着理论探索.科学技术试验的不断开展,hadoop终于2006年问世,惊天地泣鬼神! hadoop雏形开始于2002年的Apache的Nutch,Nutch是一个开源Java ...
- Git权威指南 读笔(4)
第12章 改变历史: $ git commit --amend -m "Remove hello.h, which is useless." 修改提交说明 $ git log -- ...
- Adapting to views using css or js
using css @media screen and (-ms-view-state: fullscreen-landscape) { } @media screen and (-ms-view-s ...
- C#基础|面向对象之多态
什么是多态 一句话解释,同一种事物表现出的多种形态. 看完以后,应该还是蒙的,还是看代码吧.. 现有Person类,Student类,Teacher类 其中Person类是Student和Te ...
- 标准初始化css样式表
body { font-size:12px; line-height:1.3; font-family:'微软雅黑', Tahoma,Helvetica,Arial,'宋体', sans-serif; ...
- .bat批处理脚本让cmd命令行提示符cd到工作目录 (转)
打开cmd,检查命令行提示符所在的默认位置(目录),进入该目录用notepad++创建一个文件,输入 @echo offrem 这个符号表示该行是注释.rem 进入f盘,需要先切换盘符,成功后才能进入 ...
- BZOJ 3997 [TJOI 2015 组合数学] 解题报告
这个题我脑洞了一个结论: 首先,我们定义满足以下条件的路径为“从右上到左下的路径”: 对于路径上任何不相同的两个点 $(x_1, y_1)$,$(x_2, y_2)$,都有: $x_1\neq x_2 ...