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 ...
随机推荐
- mysql 5.6.33发布
2016-09-06,mysql 5.6.33社区版发布,修复的bug越发减少,而且基本上都是较少使用的特性.
- [git] ignore文件规则失效
背景 在某次项目,发现已经将.iml规则写进.ignore文件,但是对.iml的修改依然会出现在changelist中. 解决方案 先引用git官网上的描述 gitignore - Specifies ...
- django配置fcgi参数解释
manage.py runfcgi minspare=50 maxspare=200 maxchildren=1000 maxrequests=99999 host=127.0.0.1 port=80 ...
- webpack常用的插件安装命令
webpack常用的插件安装命令:1:npm install html-webpack-plugin --save-dev //自动快速的帮我们生成HTML.2:npm install css-loa ...
- JavaScript基础12——js的方法重载
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Unable to start activity ComponentInfo{com.first/com.first.Game}
原因一: xxx的错误,若为R.layout.main 那么应该是main.xml文件中的标签 使用错误,最常见的而且编译器不会提示的错误就是 android:name 和android:id 两者 ...
- Effective Java 阅读笔记——枚举和注解
30:用enum代替int常量 当需要一组固定常量的时候,应该使用enum代替int常量,除了对于手机登资源有限的设备应该酌情考虑enum的性能弱势之外. 31:用实例域代替序数 应该给enum添加i ...
- 使用ObjectOutputStream进行socket通信的时候出现固定读到四个字节乱码的问题
问题描述: 最近在写一个通信相关的项目,服务器端和客户端通过socket进行通信.本来想利用read的阻塞特性,服务器端和客户端按照一定的流程进行文件读写.结果发现客户端或者服务器read方法一直都返 ...
- Android开发笔记——常见BUG类型之内存泄露与线程安全
本文内容来源于最近一次内部分享的总结,没来得及详细整理,见谅. 本次分享主要对内存泄露和线程安全这两个问题进行一些说明,内部代码扫描发现的BUG大致分为四类:1)空指针:2)除0:3)内存.资源泄露: ...
- iOS 秒数转换成时间,时,分,秒
//转换成时分秒 - (NSString *)timeFormatted:(int)totalSeconds{ int seconds = totalSeconds % 60; int min ...