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 ...
 
随机推荐
- Vijos1459 车展  (数学)
			
描述 遥控车是在是太漂亮了,韵韵的好朋友都想来参观,所以游乐园决定举办m次车展.车库里共有n辆车,从左到右依次编号为1,2,…,n,每辆车都有一个展台.刚开始每个展台都有一个唯一的高度h[i].主管已 ...
 - Android基础类之BaseAdapter
			
转:http://www.cnblogs.com/mandroid/archive/2011/04/05/2005525.html Android基础类之BaseAdapter BaseAdapter ...
 - JS触发事件大全
			
事件 浏览器支持 解说 一般事件 onclick IE3.N2 鼠标点击时触发此事件 ondblclick IE4.N4 鼠标双击时触发此事件 onmousedown IE4.N4 按下鼠 ...
 - php 数组二分法查找函数
			
找到返回对应的key,找不到返回-1,注意二分查找需要数组有序,下边函数需要数组递增排序. function binarySearch($arr,$x){ $start=0; $end=count($ ...
 - 设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1
			
注:这里inc方法和dec方法加synchronized关键字是因为当两个线程同时操作同一个变量时,就算是简单的j++操作时,在系统底层也是通过多条机器语句来实现,所以在执行j++过程也是要耗费时间, ...
 - dns (域名系统)
			
dns (域名系统) DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP ...
 - 如何快速读懂大型C++程序代码
			
要搞清楚别人的代码,首先,你要了解代码涉及的领域知识,这是最重要的,不懂领域知识,只看代码本身,不可能搞的明白.其次,你得找各种文档:需求文档(要做什么),设计文档(怎么做的),先搞清楚你即将要阅读是 ...
 - spring JTA多数据源事务管理详细教程
			
<context:annotation-config /> <!-- 使用注解的包路径 --> <context:component-scan base-package= ...
 - cf.VK CUP 2015.B.Mean Requests
			
Mean Requests time limit per test 4 seconds memory limit per test 256 megabytes input standard input ...
 - 以DDD为开发模式的设计开发步骤可以是
			
以DDD为开发模式的设计开发步骤可以是:1)分析需求:2)画出用例图,系统中各个角色如何使用系统,也包括外部系统如何使用系统,也包括系统中到某个时间点自动启动的某些功能(此时角色就是时间):3)针对各 ...