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不能超过最大值. ...
随机推荐
- codeforces Round 286# problem A. Mr. Kitayuta's Gift
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked ...
- 胸腺嘧啶“T”
4.下列物质或结构中含胸腺嘧啶“T”的是( )A.DNA聚合酶 B.烟草花叶病毒C.ATP D.B淋巴细胞中的线粒体
- JAVA泛型? T K V E含义
? 表示不确定的java类型,类型是未知的. T 表示java类型. K V 分别代表java键值中的Key Value. E 代表Element,特性是枚举.
- Azure + vsftpd + ubntu14 + 虚拟用户 遇到的问题:从网上摘抄
:在Azure安装好ubuntu虚拟机,安装包选择ubuntu14.04 LTS,选择LTS,以便微软对其以后的更好支持,不选就可能技术支持不会很久,现只开一台,端口默认选择22 :打开虚拟机,进入端 ...
- 创建本地Ubuntu镜像
参考文档 http://www.howtoforge.com/local_debian_ubuntu_mirror 安装服务 : sudo apt-get install apt-mirror apa ...
- linux服务器报No space left on device错误的解决过程记录
起因 今天在本地提交了点代码,但到服务器上git pull的时候提示No space left on device,第一反应是猜想可能硬盘满了(很有可能是log导致的),不过想想又觉得不太可能,这台服 ...
- CSS的IE6、IE7、FF兼容性写法
blue;< /td> Firefox 背景变蓝色 red /9; IE8 背景变红色 *black;< /td> IE7 背景变黑色 _background:orange; ...
- C# 发邮件类可发送附件
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Ne ...
- Log Parser 2.2
Log Parser 2.2 是一个功能强大的通用工具,它可对基于文本的数据(如日志文件.XML 文件和 CSV 文件)以及 Windows 操作系统上的重要数据源(如事件日志.注册表.文件系统和 A ...
- JDBC ----常用数据库的驱动程序及JDBC URL:
常用数据库的驱动程序及JDBC URL: Oracle数据库: 驱动程序包名:ojdbc14.jar 驱动类的名字:oracle.jdbc.driver.OracleDriver JDBC URL ...