poj3278 Catch That Cow(简单的一维bfs)
http://poj.org/problem?id=3278
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 47010 | Accepted: 14766 |
Description
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting.
* 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?
Input
Output
Sample Input
5 17
Sample Output
4
Hint
数组必须开大点
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h> using namespace std;
struct node
{
int x,ans;
} q[];
int jx[]= {-,};
int n,k;
int map[],v[];
void bfs()
{
struct node t,f;
int e=,s=;
t.x=n;
v[t.x]=;
t.ans=;
q[e++]=t;
while(s<e)
{
t=q[s++];
if(t.x==k)
{
printf("%d\n",t.ans);
break;
}
for(int i=; i<; i++)
{
if(i==)
f.x=t.x*;
else f.x=t.x+jx[i];
if(!v[f.x]&&f.x>=&&f.x<=)
{
f.ans=t.ans+;
q[e++]=f;
v[f.x]=;
}
}
}
}
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
memset(map,,sizeof(map));
memset(v,,sizeof(v));
bfs();
}
return ;
}
poj3278 Catch That Cow(简单的一维bfs)的更多相关文章
- POJ3278——Catch That Cow(BFS)
Catch That Cow DescriptionFarmer John has been informed of the location of a fugitive cow and wants ...
- POJ3278 Catch That Cow —— BFS
题目链接:http://poj.org/problem?id=3278 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total S ...
- poj3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 73973 Accepted: 23308 ...
- POJ3278——Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 114140 Accepted: 35715 ...
- 牛客假日团队赛5 L Catch That Cow HDU 2717 (BFS)
链接:https://ac.nowcoder.com/acm/contest/984/L 来源:牛客网 Catch That Cow 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 3 ...
- POJ3278 Catch That Cow(BFS)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- POJ 3278 Catch That Cow(简单BFS)
题目链接:http://poj.org/problem?id=3278 题目大意:给你两个数字n,k.可以对n执行操作(n+1,n-1,n*2),问最少需要几次操作使n变成k. 解题思路:bfs,每次 ...
- poj-3278 catch that cow(搜索题)
题目描述: Farmer John has been informed of the location of a fugitive cow and wants to catch her immedia ...
- POJ - 3278 Catch That Cow 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
随机推荐
- sohu_news搜狐新闻类型分类
数据获取 数据是从搜狐新闻开放的新闻xml数据,经过一系列的处理之后,生成的一个excel文件 该xml文件的处理有单独的处理过程,就是用pandas处理,该过程在此省略 import numpy a ...
- linux下的文件解压命令
说一下tar命令的参数含义:z,使用gzip解压,x:extract解压,v:显示详细信息,f:使用归档在当前文件夹. 在解压时出现了解压失败,原因是没有sudo,无法创建文件夹.
- 命名空间与Autoload
命名空间是为了防止函数名冲突 当php编译器找到未定义类时,就会自动去调用__autoload($class)这个函数,$class就代表这个未定义的类名相对于当前项目根目录所在路径 php5.3 ...
- Python----八荣八耻
以动手实践为荣 , 以只看不练为耻; 以打印日志为荣 , 以单步跟踪为耻; 以空格缩进为荣 , 以制表缩进为耻; 以单元测试为荣 , 以人工测试为耻; 以模块复用为荣 , 以复制粘贴为耻; 以多态应用 ...
- easyui---tree异步加载
1.ul li的多级列表的html代码tree 2.利用jquery <ul id="tt"></ul> $('#tt').tree({ url:'tree ...
- MySQL主从同步添加至zabbix监控
参考文档:https://blog.csdn.net/hellowidow_2020/article/details/78985368 https://www.cnblogs.com/cdjia ...
- db2 tablespaces table bufferpools reorgs
通过快照查看表空间 表 缓冲池信息 db2 get snapshot for tablespaces on teps > tablespace.infodb2 get snapshot for ...
- 联想y720 淋了雨,字体变得模糊了
显卡驱动没有问题 重新校准显示器问题解决 事实上,可能是某些软件 扰乱了系统字体,请安装上述来重新调整显示器的字体清晰度
- [No0000150]VSVisualStudio提示图标,信号图标的含义
其右侧的图标表示这是一个接口类型__interface(或者是结构体类型) 其右侧图标表示这是一个类类型 其右侧图标表示这是一个.cpp文件(貌似还可以是.hpp等文件) 其右侧图标表示这是一个枚举类 ...
- Js高设笔记 & 声明变量与初始化变量
第三章 数据类型 P25 1, var message; //age变量尚未声明 alert(message); //"undefined" alert(age); ...