Catch That Cow(poj 3278)
给定两个整数n和k
通过 n+1或n-1 或n*2 这3种操作,使得n==k
输出最少的操作次数
//广搜,a是队列,step记录步数,vis记录哪些数被搜到过
#include<cstdio>
#include<iostream>
#define M 1000010
using namespace std;
int step[M],a[M],vis[M];
int main()
{
int n,m,head=,tail=;
scanf("%d%d",&n,&m);
a[]=n;
vis[n]=;
while(head<tail)
{
++head;
int u=a[head];
if(u==m)
{
printf("%d",step[head]);
return ;
}
if(u->=&&!vis[u-])
{
a[++tail]=u-;
step[tail]=step[head]+;
vis[u-]=;
}
if(u+<&&!vis[u+])
{
a[++tail]=u+;
step[tail]=step[head]+;
vis[u+]=;
}
if(u*<&&!vis[u*])
{
a[++tail]=u*;
step[tail]=step[head]+;
vis[u*]=;
}
}
return ;
}
Catch That Cow(poj 3278)的更多相关文章
- Catch That Cow (POJ - 3278)(简单BFS)
转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82693928作者:Mercury_Lc 题目链接 题解:给你x.y,x可以加1.减 ...
- POJ 3278 Catch That Cow(求助大佬)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 109702 Accepted: 34255 ...
- 【OpenJ_Bailian - 4001】 Catch That Cow(bfs+优先队列)
Catch That Cow Descriptions: Farmer John has been informed of the location of a fugitive cow and wan ...
- POJ 3278 Catch That Cow(模板——BFS)
题目链接:http://poj.org/problem?id=3278 Description Farmer John has been informed of the location of a f ...
- POJ 3278 Catch That Cow(BFS 剪枝)
题目链接:http://poj.org/problem?id=3278 这几次都是每天的第一道题都挺顺利,然后第二道题一卡一天. = =,今天的这道题7点40就出来了,不知道第二道题在下午7点能不能出 ...
- POJ——3278 Catch That Cow(BFS队列)
相比于POJ2251的三维BFS,这道题做法思路完全相同且过程更加简单,也不需要用结构体,check只要判断vis和左右边界的越界情况就OK. 记得清空队列,其他没什么好说的. #include< ...
- HDU 2717 Catch That Cow (深搜)
题目链接 Problem Description Farmer John has been informed of the location of a fugitive cow and wants t ...
- Catch That Cow(广搜)
个人心得:其实有关搜素或者地图啥的都可以用广搜,但要注意标志物不然会变得很复杂,想这题,忘记了标志,结果内存超时: 将每个动作扔入队列,但要注意如何更简便,更节省时间,空间 Farmer John h ...
- poj-3278 catch that cow(搜索题)
题目描述: Farmer John has been informed of the location of a fugitive cow and wants to catch her immedia ...
随机推荐
- 升级OSX 10.9 Mavericks后,会导致Finder始终无响应的一个问题
刚升了OS X 10.9 Mavericks ,发现Finder始终“未响应”(Application Not Responding),查了苹果官网论坛,国内的论坛,解决方法都无效,最后各种尝试,发现 ...
- IOCP I/O完成端口(了解)
IOCP(I/O Completion Port,I/O完成端口)是性能最好的一种I/O模型.它是应用程序使用线程池处理异步I/O请求的一种机制.在处理多个并发的异步I/O请求时,以往的模型都是在接收 ...
- ssh事务配置
<!-- 配置业务层 --> <bean id="employeeService" class="cn.bdqn.jboa.service.impl.E ...
- ssh框架整合完整版
1.导入jar包 可以在src下添加一个log4j.properties文件来记录日志 2.加入实体类+映射文件 映射:从类入手class+属性 a.映射的头文件在:hibernate3.jar--& ...
- C# Web开发打开下载对话框代码
一个按钮的事件中写: string filename = Sever.UrlEncode("词库.txt"); Response.AddHeader("Content-D ...
- Spark-1.0.0 standalone分布式安装教程
Spark目前支持多种分布式部署方式:一.Standalone Deploy Mode:二Amazon EC2.:三.Apache Mesos:四.Hadoop YARN.第一种方式是单独部署,不需要 ...
- Nginx反向代理 负载均衡
nginx 这个轻量级.高性能的 web server 主要可以干两件事情: 〉直接作为http server(代替apache,对PHP需要FastCGI处理器支持): 〉另外一个功能就是作为反向代 ...
- MVC中的_viewstart.cshtml(没有设置Layout却引用了布局)
今天Home视图中新增了一个视图,因为不需要设置Layout就没与管他,但是运行起来一看,自动引用了布局,分析了半天 也没看出是哪的错误? 后来尝试着在area中增加了一个同样的视图就没有问题,比较这 ...
- Android学习笔记之打钩显示输入的密码
利用EditText作为密码输入框是个不错的选择(只需设置输入类型为textPassword即可),保密且无需担心被盗取.但有时用户也不知道自己输入的是否正确,这时就应该提供一个“显示密码”的复选框, ...
- IOS 页面之间的跳转
1.UINavigationController popToViewController 对应popViewControllerAnimated: 也可以使用: [self.navigationCon ...