POJ 3248 Catch That Cow
http://poj.org/problem?id=3278
二维BFS
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#define READ() freopen("in.txt", "r", stdin); using namespace std; struct Loc
{
int x, step;
Loc () {}
Loc(int x, int step) : x(x), step(step) {}
}; int N, K;
bool use[];
bool OK(int x)
{
if (x < || x > ) return false;
else return true;
}
int bfs()
{
queue<Loc> que;
que.push(Loc(N, ));
while (!que.empty())
{
Loc crt = que.front();
que.pop();
if(use[crt.x]) continue;
use[crt.x] = true;
int nx = crt.x - ;
if (OK(nx) && !use[nx])
{
if (nx == K) return crt.step+;
else que.push(Loc(nx, crt.step+));
}
nx = crt.x + ;
if (OK(nx))
{
if (nx == K && !use[nx]) return crt.step+;
else que.push(Loc(nx, crt.step+));
}
nx = *crt.x;
if (OK(nx) && !use[nx])
{
if (nx == K) return crt.step+;
else que.push(Loc(nx, crt.step+));
}
}
}
int main()
{
//READ()
scanf("%d%d", &N, &K);
if (N == K) //有N == K的坑点 严谨一点
{
cout << << endl;
return ;
}
memset(use, , sizeof(use));
int ans = bfs();
cout << ans << endl;
return ;
}
POJ 3248 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(BFS,板子题)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 88732 Accepted: 27795 ...
- 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: 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 ...
随机推荐
- H+后台主题UI框架---整理(三)
这里面介绍下H+后台主题UI框架里面插件的应用,不过都是最最简单最初级的功能.主要有日历插件,input单选多选(icheck)插件,input下拉搜索(chosen)插件. 一.日历插件 有如下几种 ...
- web前端工程师入门须知
本文是写给那些想要入门web前端工程的初学者,高手请路过,也欢迎高手们拍砖. 先说下web前端工程师的价值,目前web产品交互越来越复杂,用户使用体验和网站前端性能优化这些都得靠web前端工程师去做w ...
- Cognos邮件发送
1.打开报表,点击下图的标记 2.设置发送格式收件人 3.设置报表格式 4.设置发送内容
- 自制Jquery下拉框插件
(function ($) { $.fn.select3 = function (option) { $(this).each(function () { var _this = $(this); v ...
- caffe proto
所在目录为: /src/caffe/proto 在caffe.proto中定义了很多结构化数据,比如LayerParameter.Datum.NetParameter.SolverParameter. ...
- RestTemplate-postForObject源码
参数: 请求路径, 请求参数, 返回类型, 扩展模板变量
- “xxxx”表 - 无法修改表。 不能将值 NULL 插入列 'xxxx'
问题 向已有表增加字段 执行下面sql,sql执行增加两个字段分别: articleTitle 正标题 [nvarchar](200) articleSubTitle 副标题 [nvarchar](2 ...
- 调试bug方法总结
打印法 debugger 分段屏蔽法 有没有涉及到异步.延迟请求 渲染顺序
- ZOJ - 1655 Transport Goods(单源最长路+迪杰斯特拉算法)
题目: 有N-1个城市给首都(第N个城市)支援物资,有M条路,走每条路要耗费一定百分比(相对于这条路的起点的物资)的物资.问给定N-1个城市将要提供的物资,和每条路的消耗百分比.求能送到首都的最多的物 ...
- nginx解决跨域(前后端分离)
Nginx解决跨域问题 后端接口 请求地址 返回数据(json数据) http://127.0.0.1:8080//app Hello World! 前端代码 通过nginx做静态资源服务器访问端口8 ...