HDU 1896 Stones --优先队列+搜索
一直向前搜。。做法有点像模拟。但是要用到出队入队,有点像搜索。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
#define N 100003 struct node
{
int p,d;
bool operator <(const node &a)const
{
if(p == a.p)
return d>a.d;
return p>a.p;
}
}stone[N]; int maxdis;
priority_queue<node> que; void GO()
{
node now,next;
int OE = ;
while(!que.empty())
{
now = que.top();
que.pop();
if(OE)
{
next.p = now.p + now.d;
next.d = now.d;
que.push(next);
maxdis = max(next.p,maxdis);
OE = ;
}
else
OE = ;
}
} int main()
{
int t,i,p,d,n;
scanf("%d",&t);
while(t--)
{
maxdis = ;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d%d",&stone[i].p,&stone[i].d);
que.push(stone[i]);
}
GO();
printf("%d\n",maxdis);
}
return ;
}
HDU 1896 Stones --优先队列+搜索的更多相关文章
- 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<cstring> #include<queue> ...
- hdu 1896.Stones 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...
- hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的 ...
- Hdu2425-Hiking Trip(优先队列搜索)
Hiking in the mountains is seldom an easy task for most people, as it is extremely easy to get lost ...
- HDU 1896:Stones(优先队列)
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- Stones HDU 1896
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大意: 有n个石头,每个石头有:p 它所在的位置 ,d 它能扔多远 从0 开始,遇到第奇 ...
- hdoj 1896 Stones【优先队列】
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
随机推荐
- Orchard MySql 修正版 下载
Orchard是支持多种数据库的如果是个人站长推荐使用MySql作为运行数据库,虽然SqlServer更为强大,但总觉得SqlServer好重啊,一装就是几个G. 最近的版本在使用MySql建库时却会 ...
- jdk1.8 ThreadPoolExecutor实现机制分析
ThreadPoolExecutor几个重要的状态码字段 private static final int COUNT_BITS = Integer.SIZE - 3; private static ...
- Fundamentals of speech signal processing
PDF版资料下载:链接:http://pan.baidu.com/s/1hrKntkw 密码:f2y9
- javascript-this,call,apply,bind简述2
上节我们一起研究了this这个小兄弟,得出一个结论,this指向调用this所在函数(或作用域)的那个对象或作用域.不太理解的朋友可以看看上节的内容,这次我们主要探讨一下call(),apply(), ...
- SAP中获取当前用户相关信息的两个函数
函数名:TH_USER_LIST作用:可以得到SM04界面显示样式的表. 函数名:TH_USER_INFO作用:可以得到当前特定用户的机器名.当前活动窗口数.IP地址等信息
- iOS 模仿微信的照片选择器
功能和微信的基本一致. 这个选择器使用了循环方式,保证在浏览图片时内存中只加载最多3张图片.稳定的内存大小,可定义图片尺寸.详细说明在github. 下载地址: https://github.com/ ...
- [Android]ViewPager如何只初始化一个页面
使用过ViewPager的应该都知道,ViewPager的setoffscreenpagelimit()方法,使用该方法可以设置在ViewPager滑动时,左右两侧各保存多少个页面,那我们直接设置se ...
- Hibernate学习0.Hibernate入门
Hibernate是什么 面向java环境的对象/关系数据库映射工具. 1.开源的持久层框架. 2.ORM(Object/Relational Mapping)映射工具,建立面向对象的域模型和关系数据 ...
- Atitit。 《吠陀》 《梨俱吠陀》overview 经读后感 是印度上古时期一些文献的总称
Atitit. <吠陀> <梨俱吠陀>overview 经读后感 是印度上古时期一些文献的总称 1. 印度古<吠陀>经,是印度上古时期一些文献的总称, 1 1.1 ...
- TOMCAT报错:HTTP Status 404 -
构建struts2工程师,tomcat报错: HTTP Status 404 - type Status report message description The requested resour ...