poj3278
#include<iostream>
#define MAX 100001
int john,cow;
int queue[MAX];
int vis[MAX];
int ans; void bfs()
{
int tail,head;
tail=head=;
int start=john;
queue[tail++]=start;
vis[start]=;
while(head!=tail)
{
int cur,next;
cur=queue[head++];
if(cur==cow)
{
ans=vis[cur]-;
return;
}
next=cur;
next=cur+;
if(next>=&&next<MAX&&vis[next]==)
{
vis[next]=vis[cur]+;
queue[tail++]=next;
} next=cur-;
if(next>=&&next<MAX&&vis[next]==)
{
vis[next]=vis[cur]+;
queue[tail++]=next;
}
next=*cur;
if(next>=&&next<MAX&&vis[next]==)
{
vis[next]=vis[cur]+;
queue[tail++]=next;
}
}
} int main()
{
//freopen("input.txt","r",stdin);
std::cin>>john>>cow;
for(int i=;i<MAX;i++)
vis[i]=;
bfs();
std::cout<<ans;
return ;
}
poj3278的更多相关文章
- poj3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 73973 Accepted: 23308 ...
- ACM/ICPC 之 BFS-广搜+队列入门-抓牛(POJ3278)
这一题是练习广度优先搜索很好的例题,在很多广搜教学中经常用到,放在这里供学习搜索算法的孩纸们看看= = 题目大意:一维数轴上,农夫在N点,牛在K点,假定牛不会移动,农夫要找到这头牛只能够进行以下三种移 ...
- POJ3278——Catch That Cow(BFS)
Catch That Cow DescriptionFarmer John has been informed of the location of a fugitive cow and wants ...
- 暑假集训(1)第二弹 -----Catch the cow(Poj3278)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- POJ-3278(BFS)
题目: ...
- poj3278 BFS入门
M - 搜索 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:65536KB 64bit I ...
- POJ3278 Catch That Cow(BFS)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- poj3278(bfs)
题目链接:http://poj.org/problem?id=3278 分析:广搜,每次三种情况枚举一下,太水不多说了. #include <cstdio> #include <cs ...
- 超超超简单的bfs——POJ-3278
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 89836 Accepted: 28175 ...
随机推荐
- sqlite基础
常用命令 sqlite3提供的特殊命令, 以.开头: .help: 帮助 .databases: 列出数据库 .tables: 列出表名 .open dbname: 打开数据库 .save dbnam ...
- haproxy+keepalived(涵盖了lvs,nginx.haproxy比较)
文章转载自: haproxy+keepalived https://cloud.tencent.com/developer/article/1026385 网络四层和七层的区别 https: ...
- aiohttp文档翻译-server(一)
web server 快速入门 运行一个简单的web server 为了实现web server, 首先需要实现request handler 一个 request handler 必须是一个coro ...
- Nginx 学习专栏
Nginx 入门学习教程 译:Centos7 编译安装Nginx 教程
- 如何免费的将本地Web服务映射到外网
链接地址:https://hongmaju.github.io/2018/05/13/ngrok%E5%B0%86%E6%9C%AC%E5%9C%B0Web%E6%9C%8D%E5%8A%A1%E6% ...
- 【iCore4 双核心板_FPGA】实验十九:使用JTAT UART终端打印信息
实验指导书及源代码下载地址: 链接:https://pan.baidu.com/s/1c3mqDkW 密码:4x9h iCore4链接:
- 加载所有jar包下指定文件
加载所有jar包下指定文件: 如spring中加载 META-INF/spring.handlers 加载 org.springframework.core.io.support.Properties ...
- SpringBoot2.X + SpringCache + redis解决乱码问题
环境:SpringBoot2.X + SpringCache + Redis Spring boot默认使用的是SimpleCacheConfiguration,使用ConcurrentMapCach ...
- python定义函数时,形参前加*和**的意义
转发:https://blog.csdn.net/qq_34806812/article/details/82017839 1.加*表示接受一个tuple类型(元组),如: 2.加**表示接受一个di ...
- Scala学习笔记(七):Rational、隐式转换、偏函数、闭包、重复参数及柯里化
class Rational(n: Int, d: Int) { require(d != 0) private val g: Int = gcd(n, d) val number: Int = n ...