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 Vi的使用
1.vi使用三模式:一般模式,插入模式,命令模式 保存和退出vi: 命令模式下 :w 保存 :w 新文件 保存到新文件 类似另存为,新文件存在,报错 :w! 新文件 保存到新文件,新文件存在,覆盖 : ...
- Google设计理念
Google的十大信条 我们首次拟就这“十大信条”还是在Google刚刚成立没几年的时候.此后,我们时常重新审视这份清单,看看它是否依然适用.我们希望这些信条永不过时,而您也可以监督我们是否遵守了这些 ...
- 51nod1057 N的阶乘
输入N求N的阶乘的准确值. Input 输入N(1 <= N <= 10000) Output 输出N的阶乘 Input示例 5 Output示例 120参考博客:blog.csdn. ...
- mysql批量更新、多表更新、多表删除
本文介绍下,mysql中进行批量更新.多表更新.多表删除的一些实例,有需要的朋友可以参考下. 本节主要内容: mysql的批量更新.多表更新.多表删除 一,批量更新: 复制代码代码示例: update ...
- Web应用工作流程总结
了解Web应用的工作过程有益于Web测试时更好的理解,Web应用工作的过程分为以下5个步骤: 1. 用户在Web浏览器中输入一个Web地址.选择一个超链接或点击一个按钮 2. Web浏览器将用户的动作 ...
- MVC-各种传值方式
[转自]:QLeelulu示例一:ViewData传值.HomeController.cs Co de: public ActionResult Index(){ ViewData[" ...
- 图片上传并显示(兼容ie),图片大小判断
图片上传并显示(兼容ie),图片大小判断 HTML <div id="swf" style="margin: 0 auto;text-align: center;& ...
- java连接mysql数据库(jsp显示和控制台显示)
很多事情,在我们没有做之前我们觉得好难,但是只要你静下心来,毕竟这些都是人搞出来的,只要你是人,那就一定可以明白. 配置:JDK1.8,MySQL5.7,eclipse:Neon Rel ...
- BZOJ 3992 [SDOI 2015] 序列统计 解题报告
这个题最暴力的搞法就是这样的: 设 $Dp[i][j]$ 为前 $i$ 个数乘积为 $j$ 的方案数. 转移的话就不多说了哈... 当前复杂度 $O(nm^2)$ 注意到,$M$ 是个质数,就说明 $ ...
- 【深度学习系列2】Mariana DNN多GPU数据并行框架
[深度学习系列2]Mariana DNN多GPU数据并行框架 本文是腾讯深度学习系列文章的第二篇,聚焦于腾讯深度学习平台Mariana中深度神经网络DNN的多GPU数据并行框架. 深度神经网络( ...