POJ 3278 Catch That Cow
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <cmath>
#include <cctype>
#define N 200010
using namespace std; bool maps[N];//用来判断此点约翰有没有走过
int a, b, step[N];//a, b 为分别为N, K, //step[i]用来保存约翰走到i点时用了几步 (注 : 不要用结构体保存步数, 不然有可能MLE) void BFS()
{
int q1 = a;
maps[a] = true;
queue<int>q;
q.push(q1); while(!q.empty()) {
int q2 = q.front();
q.pop();
if(q2 == b) {//找到之后输出走了几步
printf("%d\n", step[q2]);
return ;
}
//约翰向走 -1 只有此时他的坐标为正数才会走
int x = q2 - ;
if(!maps[x] && q2 > ) {
maps[x] = true;
q1 = x;
step[q1] = step[q2] + ;
q.push(q1);
}
//由于约翰向后走只能 -1 所以只在q2 < b时才向前走
if(q2 < b){
x = q2 + ;
if(!maps[x]) {
maps[x] = true;
q1 = x;
step[q1] = step[q2] + ;
q.push(q1);
}
x = q2 * ;
if(!maps[x]) {
maps[x] = true;
q1 = x;
step[q1] = step[q2] + ;
q.push(q1);
}
} }
} int main()
{
while(~scanf("%d %d", &a, &b)){
memset(maps, , sizeof(maps));
BFS();
}
return ;
}
POJ 3278 Catch That Cow的更多相关文章
- BFS POJ 3278 Catch That Cow
题目传送门 /* BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 */ #include <cstdio> #include <iostream> #inc ...
- POJ 3278 Catch That Cow(赶牛行动)
POJ 3278 Catch That Cow(赶牛行动) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Farmer J ...
- POJ 3278 Catch That Cow (附有Runtime Error和Wrong Answer的常见原因)
题目链接:http://poj.org/problem?id=3278 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total S ...
- POJ 3278 Catch That Cow(BFS,板子题)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 88732 Accepted: 27795 ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- poj 3278:Catch That Cow(简单一维广搜)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45648 Accepted: 14310 ...
- poj 3278 Catch That Cow (bfs搜索)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 46715 Accepted: 14673 ...
- POJ 3278 Catch That Cow[BFS+队列+剪枝]
第一篇博客,格式惨不忍睹.首先感谢一下鼓励我写博客的大佬@Titordong其次就是感谢一群大佬激励我不断前行@Chunibyo@Tiancfq因为室友tanty强烈要求出现,附上他的名字. Catc ...
- poj 3278 catch that cow BFS(基础水)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 61826 Accepted: 19329 ...
- POJ - 3278 Catch That Cow BFS求线性双向最短路径
Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...
随机推荐
- javascript中怎样区分元素和节点?
1.所谓元素,即html文档里面,所有的标签都可以称之为元素,比如说<p>.<tr>等,也就是说元素是个统称,一个文档里面有很多的元素.2.所谓节点,是js为了对html文档进 ...
- 在iOS中使用OpenSSL的Public Key 进行加密
这几天一直潜心于iOS开发,刚好把遇到的问题都记录一下.这次遇到的问题就是如果根据得到的Public Key在iOS 客户端对用户名和密码进行加密. Public Key如下: -----BEGIN ...
- linux批量查找文件内容
find ./ -name "*.php" | xargs grep '要查找的内容' 如果需要查找的内容包含特殊符号,比如$等等,grep要加参数 find ./ -name & ...
- python学习总结03
1.开启虚拟技术 1.1 安装virtualenv 1.1.1 在python环境中运行pip install virtualenv 出现如下信息表示安装成功 1.1.2 进入python的Scrip ...
- s5pv210启动debian出错提示bash: cannot set terminal process group (-1): Inappropriate ioctl for device
1.启动参数如下: bootargs=root=/dev/nfs nfsroot=192.168.1.8:/opt/wheezy_fs ip=192.168.1.9:192.168.1.8:192.1 ...
- shell编程之变量
变量: 变量由字母.数字._ 组成,不能以数字开头 长度不能超过255个字符 在bash中,变量的默认类型是字符串类型 变量分类: 1.用户自定义变量:只在当前shell生效,是局部变量 定义方法: ...
- OpenCV从入门到放弃系列之——core模块.核心功能(一)
Mat - 基本图像容器 世间的图像是各种各样的,但是到了计算机的世界里所有的图像都简化为了数值矩以及矩阵信息.作为一个计算视觉库,OpenCV的主要目的就是处理和操作这些信息,来获取更高级的信息,也 ...
- sublime-text3 3059基本配置
1.下载安装官方版注册机语言包 参考安装: http://www.xiumu.org/note/sublime-text-3.shtml 2.插件 Package ControlConvertToUT ...
- 常见的js 里对数字进行处理的函数方法集合
常见的对小数值舍入为整数的几个方法:Math.ceil().Math.floor()和Math.round(). 这三个方法分别遵循下列舍入规则: Math.ceil()执行向上舍入,即它总是将数值向 ...
- web应用动态文档技术
动态生成web文档分为服务器动态生成.客户端动态生成 服务器动态生成文档技术主要有: CGI - 公共网关接口,它是一个允许Web服务器与后端程序以及脚本进行通信的标准化接口.通常是web服务器收到一 ...