hdu 2717 Catch That Cow(BFS,剪枝)
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
struct tt
{
int step,tem;
};
int visit[];
queue <tt> q; int bfs(tt s,tt e)
{
tt front,temp;
q.push(s);
visit[s.tem]=;
while(!q.empty())
{
front=q.front();
q.pop();
temp.step=front.step+;
temp.tem=front.tem+;
if(temp.tem==e.tem)
return temp.step;
else if(temp.tem>=&&temp.tem<=&&visit[temp.tem]==) q.push(temp),visit[temp.tem]=; temp.tem=front.tem-;
if(temp.tem==e.tem)
return temp.step;
else if(temp.tem>=&&temp.tem<=&&visit[temp.tem]==) q.push(temp),visit[temp.tem]=; temp.tem=front.tem*;
if(temp.tem==e.tem)
return temp.step;
else if(temp.tem>=&&temp.tem<=&&visit[temp.tem]==) q.push(temp),visit[temp.tem]=;
}
return ;
} int main()
{
tt s,e;
int ans;
while(scanf("%d%d",&s.tem,&e.tem)!=EOF)
{
s.step=;
memset(visit,,sizeof(visit));
while(!q.empty())
q.pop();
if(s.tem<e.tem)
ans=bfs(s,e);
else
ans=s.tem-e.tem;
printf("%d\n",ans);
}
return ;
}
hdu 2717 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,最先 ...
- HDU 2717 Catch That Cow (bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2717 Catch That Cow Time Limit: 5000/2000 MS (Java/Ot ...
- HDU 2717 Catch That Cow(常规bfs)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2717 Catch That Cow Time Limit: 5000/2000 MS (Java/Oth ...
- hdu 2717:Catch That Cow(bfs广搜,经典题,一维数组搜索)
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 2717 Catch That Cow(BFS)
Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...
- hdu 2717 Catch That Cow(广搜bfs)
题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...
- 杭电 HDU 2717 Catch That Cow
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 题解报告:hdu 2717 Catch That Cow(bfs)
Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...
- HDOJ/HDU 2717 Catch That Cow 一维广度优先搜索 so easy..............
看题:http://acm.hdu.edu.cn/showproblem.php?pid=2717 思路:相当于每次有三个方向,加1,减1,乘2,要注意边界条件,减1不能小于0,乘2不能超过最大值. ...
随机推荐
- 分布式PostGIS系列【2】——pgpool-II
一.pgpool-II简介 二.pgpool-II安装与配置 三.分布式Postgis性能测试
- F. Music in Car
田园将芜胡不归?既自以心为形役,奚惆怅而独悲?悟已往之不谏,知来者之可追.实迷途其未远,觉今是而昨非. 题目链接http://codeforces.com/contest/746/problem/F ...
- ListBox复选框拓展
Toolkit的LongListMutiSelector的复选框功能,想必许多人都需要吧!然而系统本身控件ListBox虽然也有多选功能,可是外观上却缺乏复选框,选择效果只是颜色变化.于是在上一个项目 ...
- linux中的文件属性
l 是链接d 是目录c 是字符设备文件b 是块设备- 是文件
- javascript 逻辑运算符
javascript逻辑运算符 NOT(!) AND(&&) OR(||) NOT(!) 返回值的类型一定是Boolean值的 运算数也是Boolean值 返回值是:与相反的boole ...
- winform:无法引用其他类库,dll,using等个人看法【图】
在项目类库中已经引用了相关了类库,生成解决方案也没问题,但是到了后置代码,通过using引用其他类库的时候,再生成解决方案或者生成单个类库,就会报“未能找到类型或命名空间“xxx"(是否缺少 ...
- 【Qt】Qt之自定义界面(窗体缩放-跨平台终极版)【转】
简述 通过上一节内容,我们实现了窗体的缩放,功能很不错,但是很遗憾-不支持跨平台!如果对于多平台来说,这是一个硬伤,所以,我们急需要一个能够支持跨平台的实现方案. 在网上看到过很多不同的实现方式,多多 ...
- 左右滑动删除ListView条目Item--第三方开源--SwipeToDismiss
Android的SwipeToDismiss是github上一个第三方开源框架(github上的项目链接地址:https://github.com/romannurik/Android-SwipeTo ...
- (转)使用getevent监听Android输入设备文件
尊重原创转载请注明:From AigeStudio(http://blog.csdn.net/aigestudio)Power by Aige 侵权必究! 炮兵镇楼 上一节Android事件分发完全解 ...
- 《.NET简单企业应用》技术路线
前言 工作三年了,一直从事基于.NET体系的企业应用开发,心得和经验也攒了点:担心时间长了给忘了,所以得给写下来,以便以后回味回味:更重要的是能让知识系统化和体系化. 本系列以一个简单的企业应用系统为 ...