HDU2717-Catch That Cow (BFS入门)
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2717
Catch That Cow
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14880 Accepted Submission(s): 4495
* Walking: FJ can move from any point X to the points X - 1 or X + 1 in a single minute
* Teleporting: FJ can move from any point X to the point 2 × X in a single minute.
If the cow, unaware of its pursuit, does not move at all, how long does it take for Farmer John to retrieve it?
The fastest way for Farmer John to reach the fugitive cow is to move along the following path: 5-10-9-18-17, which takes 4 minutes.
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int v[],t[];
int main()
{
int n,a,b,i,f;
while(scanf("%d%d",&a,&b)!=EOF)
{
memset(t,,sizeof(t));
memset(v,,sizeof(v));
queue<int > q;
q.push(a);
v[a]=;
if(a==b)
{
printf("0\n");
continue;
}
while(!q.empty())
{
int ll=q.front(),r=ll-,l=ll+,z=ll*;
q.pop();
//printf("ll=%d\n",ll);
if(z>=&&z<=&&!v[z])
{
q.push(z);
v[z]=v[ll]+;
// printf("v[z]=%d z=%d\n",v[z],z);
}
if(l>=&&l<=&&!v[l])
{
q.push(l);
v[l]=v[ll]+;
// printf("v[l]=%d l=%d\n",v[l],l);
}
if(r>=&&r<=&&!v[r])
{
q.push(r);
v[r]=v[ll]+;
// printf("v[r]=%d r=%d\n",v[r],r);
} if(l==b||r==b||z==b)
{ break;
} } printf("%d\n",v[b]-); }
return ; }
HDU2717-Catch That Cow (BFS入门)的更多相关文章
- HDU 2717 Catch That Cow --- BFS
HDU 2717 题目大意:在x坐标上,农夫在n,牛在k.农夫每次可以移动到n-1, n+1, n*2的点.求最少到达k的步数. 思路:从起点开始,分别按x-1,x+1,2*x三个方向进行BFS,最先 ...
- POJ 3278 Catch That Cow[BFS+队列+剪枝]
第一篇博客,格式惨不忍睹.首先感谢一下鼓励我写博客的大佬@Titordong其次就是感谢一群大佬激励我不断前行@Chunibyo@Tiancfq因为室友tanty强烈要求出现,附上他的名字. Catc ...
- POJ3278——Catch That Cow(BFS)
Catch That Cow DescriptionFarmer John has been informed of the location of a fugitive cow and wants ...
- poj 3278 Catch That Cow (bfs搜索)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 46715 Accepted: 14673 ...
- POJ 3278 Catch That Cow(BFS,板子题)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 88732 Accepted: 27795 ...
- HDU2717 Catch That Cow 【广搜】
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- poj 3278 catch that cow BFS(基础水)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 61826 Accepted: 19329 ...
- POJ - 3278 Catch That Cow BFS求线性双向最短路径
Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...
- POJ3278 Catch That Cow —— BFS
题目链接:http://poj.org/problem?id=3278 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total S ...
- catch that cow (bfs 搜索的实际应用,和图的邻接表的bfs遍历基本上一样)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 38263 Accepted: 11891 ...
随机推荐
- PostgreSQL导出一张表到MySQL
1. 查看PostgreSQL表结构,数据量,是否有特殊字段值 region_il=# select count(*) from result_basic; count --------- ( row ...
- 简述Spring容器与SpringMVC的容器的联系与区别
简述Spring容器与SpringMVC的容器的联系与区别 2017年07月04日 10:55:07 阅读数:6260 摘要: 在Spring整体框架的核心概念中,容器的核心思想是管理Bean的整个生 ...
- matlab作图 latex插图
推荐用saveas eps,再用eps2pdf转成pdf.这样可以之间pdflatex编译. if result.savepic saveas(gcf,[ pwd '/picture/right_' ...
- NiXi.DAY06东软实训.:面向对象思想~抽象~static~final~构造方法及其重载
本章技能目标: 使用类图描述设计 掌握面向对象设计的基本步骤 掌握类和对象的概念 掌握构造方法及其重载 掌握封装的概念及其使用 本章单词: class:类 object:对象 static: fina ...
- Win10系列:VC++ Direct3D模板介绍2
(3)CreateDeviceResources函数 CreateDeviceResources函数默认添加在CubeRenderer.cpp源文件中,此函数用于创建着色器和立体图形顶点.接下来分别介 ...
- Win10系列:VC++ 定时器
计时器机制俗称"心跳",表示以特定的频率持续触发特定事件和执行特定程序的机制.在开发Windows应用商店应用的过程中,可以使用定义在Windows::UI::Xaml命名空间中的 ...
- TOleControl(WebBrowser1).Visible := False 这样就可以隐藏浏览器控件
TOleControl(WebBrowser1).Visible := False 这样就可以隐藏浏览器控件了. ------------------------------------------- ...
- 手动配置 Windows 时间服务
手动配置 Windows 时间服务 要将内部时间服务器配置为与外部时间源同步,请按照下列步骤操作: 将服务器类型更改为 NTP. 为此,请按照下列步骤操作: 选择 “开始” . “运行”,键入 reg ...
- 怎么搜索sci论文。
进入清华大学图书馆,选择常用数据库,找到 Web of Science平台(SCI/SSCI/AHCI.ISTP/ISSHP.DII.JCR.BP.CCC.CCR/IC.ESI.INSPEC…)即可. ...
- Driver 01 进程隐藏
大二时候的代码以及笔记,当时暂时记录在QQ上在,现在发出来分享一下. 为了写驱动装一大堆的软件插件啥的,还常常失败. 这里就顺带总结下SDK下载和WinDbg symbol路径设置正确WinDbg却总 ...