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 ...
随机推荐
- MySQL技术内幕读书笔记(二)——InnoDB存储引擎
目录 InnoDB存储引擎 InnoDB存储架构 Checkpoint技术 Master Thread 工作方式 InnoDB关键特性(放一下,感觉看后面,再看总结吧) InnoDB存储引擎 Inno ...
- Springboot整合二 集成 rabbitmq
1.在application.yml文件中进行RabbitMQ的相关配置先上代码 spring: rabbitmq: host: 192168.21.11 port: username: guest ...
- [docker]通过阿里云源安装docker && flannel不通问题解决(try this guy out)
docker清理容器 # 容器停止后就自动删除: docker run --rm centos /bin/echo "One"; # 杀死所有正在运行的容器: docker kil ...
- SQL递归方式实现省市区县级别查询
数据库脚本 CREATE TABLE [dbo].[Std_Area]( [Id] [int] NOT NULL, [Name] [nvarchar](50) NULL, [ParentId] [in ...
- PCL_common模块api代码解析
pcl_common库包含大多数PCL库使用的公共数据结构和方法.核心数据结构包括PointCloud类和许多用于表示点.表面法线.RGB颜色值.特征描述符等的点类型.它还包含许多用于计算距离/范数. ...
- OpenGL着色器入门简介
说明:本文翻译自LearnOpengl经典教程,OpenGL着色器基础介绍的比较通俗易懂,特总结分享一下! 为什么要使用着色器?我们知道,OpenGL一般使用经典的固定渲染管线来渲染对象,但是随着Op ...
- 基于FeignClient提供简单的用户查询服务
前言: 由于系统升级,之前的员工数据库(mongo库)被弃用,改为用python维护的mysql库,其他系统访问通过http请求,表结构对外不可见,其他系统之前对员工mongo库的依赖要解除.每套系统 ...
- Android实现夜间模式
如今非常多App都有夜间模式,特别是阅读类的App.夜间模式如今已经是阅读类App的标配了,其实,日间模式与夜间模式就是给App定义并应用两套不同颜色的主题,用户能够自己主动或者手动的开启,今天用An ...
- springBoot整合ftp上传图片功能
知识点: springBoot后端项目,接收前端框架传到的图片,把图片上传到ftp图片服务器上 注意:在上传的过程中可能回出现,可以创建文件夹,但是图片上传不了的问题: 尝试了网上的很多方法,最后将f ...
- C++ Addon Async 异步机制
线程队列: libuv,window 可在libuv官网下载相应版本 opencv: 编译的时候opencv的位数要和 node的bit 一致 兼容electron : node-gyp rebu ...