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容器的样例】
感谢<啊哈!算法>的讲解,水鸟弄懂了什么是优先队列. 题意是:在路上有很多石子,给出他们的初始位置和小明能够将他们扔出的距离,当小明遇到奇数个石子的时候就会把它扔出,遇到偶数个就会忽略他, ...
随机推荐
- Linux – RedHat7 / CentOS 7 忘记root密码修改
1.(a) 开机出现grub boot loader 开机选项菜单时,立即点击键盘任意鍵,boot loader 会暂停. (b) 按下’e’,编辑选项菜单(c) 移动上下鍵至linux16 核心命令 ...
- js清空web用户控件的值
假设你的用户控件里面有: <asp:DropDownList ID="DropDownList1" runat="server"> <asp: ...
- PHP+Ajax 异步通讯注册验证
HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- python引入导入自定义模块和外部文件
参考:http://blog.csdn.net/devil_2009/article/details/15816237 项目中想使用以前的代码,或者什么样的需求致使你需要导入外部的包 如果是web 下 ...
- Web应用工作流程总结
了解Web应用的工作过程有益于Web测试时更好的理解,Web应用工作的过程分为以下5个步骤: 1. 用户在Web浏览器中输入一个Web地址.选择一个超链接或点击一个按钮 2. Web浏览器将用户的动作 ...
- git reflog 和git log :no branch git 提交方式
git reflog 和git log的区别,外加git cherry-pick的一种用法 git reflog 可以查看所有分支的所有操作记录(包括(包括commit和reset的操作),包括已经被 ...
- cnn常用参数记录
1. epoch 在代码中经常见到n_epochs这个参数,该参数到底是什么意思呢?答案如下: 在一个epoch中,所有训练集数据使用一次 one epoch = one forward pass a ...
- stdout 编码 vim 删除左边,右边
sys.stdout = codecs.getwriter('utf8')(sys.stdout) vimdic['kkkk'] = qqqqqdic['bbbb'] = aaaaaadic['kkk ...
- unity Android 打包后读取 xml 文件
原地址:http://www.cnblogs.com/wuzhang/p/wuzhang20140731.html 问题: 前天在做东西的过程中发现了一个让人很纠结的问题,为什么Unity 程序 ...
- ASP.NET MVC3 Web应用程序中启用GZip压缩示例
http://www.mzwu.com/article.asp?id=3284 自定义一个筛选器,继承于GZipAttribute: using System;using System.IO.Comp ...