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. ...
随机推荐
- ubuntu下安装Python3
到www.python.org网站下载python3.3.2 Gzipped source tar ball (3.3.2) (sig), ~ 16 MB 解压tar vxzf Python3.3.2 ...
- poj1734 Sightseeing trip【最小环】
Sightseeing trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions:8588 Accepted:3224 ...
- vins-mono调试教程
https://www.cnblogs.com/Jessica-jie/p/6950604.html
- [No0000161]IDEA初步接触
安装 参考https://blog.csdn.net/qq_35246620/article/details/61191375 安装过程全程默认(路径和快捷方式自定义,不需要下载jre): 启动后全程 ...
- [No000012B]WPF(3/7)有趣的边框和画刷[译]
介绍 边框是每个WPF程序的主要构成块.在我现在的程序中,我使用了很多的边框来装饰界面.从把边框直接放到窗口中到把边框放到控件模板和列表项中,边框在创建一个好的应用界面上扮演了一个非常重要的角色.在这 ...
- [No000011E]Python教程1/9-Python简介
Python是一种计算机程序设计语言.你可能已经听说过很多种流行的编程语言,比如非常难学的C语言,非常流行的Java语言,适合初学者的Basic语言,适合网页编程的JavaScript语言等等. 那P ...
- phoenix技术(安装部署和基本使用)讲解
1.phoenix简介 Apache Phoenix是构建在HBase之上的关系型数据库层,作为内嵌的客户端JDBC驱动用以对HBase中的数据进行低延迟访问.Apache Phoenix会将用户编写 ...
- Oracle安装部署之Win7下oracle11g数据库的安装及配置
1.下载安装包 到oracle官网downloads下下载(第一次下载需要注册账号). Win7 64位下载64位oracle11g安装包 Win7 32位下载32位oracle11g(Oracle_ ...
- .net WebService的使用
1. WebService可单独作为一个网站,不限平台的被调用. 2. 打开VS,选择新建 3. [WebMethod] 方法上面有这个说明,则表示此方法可被外部调用. 我们添加4个方法:加.减.乘. ...
- ionic cordova screenshot 使用和操作
如何调用cordova 中的screenshot插件进行截图 首先添加 ionic cordova plugin add com.darktalker.cordova.screenshot npm i ...