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 ...
随机推荐
- vs2013转为vs2010项目
1.首先用记事本之类的工具打开.sln文件 打开后会看到如下信息 Format Version 12.00 就是指VS2013 VisualStudioVersion = 12.0.21005.1 指 ...
- This is such a crock of shit—From Scent of a woman
- Mr. Slade. - This is such a crock of shit! - Mr. Trask. - Please watch your language, Mr. Slade. Y ...
- iPhone4 offical AD
iPhone4 is so much more than just a new products.I mean this would have a lot of impact on the way i ...
- 一段字符串中间提取json字符串
项目过程中经常打日志:LOG.error("[failure][CreateOrder] param:{}", JSON.toJSONString(userCreateOrderD ...
- Delphi7中使用Indy9的IdSmtp发送email时subject过长会出现乱码的解决办法
procedure TIdMessageClient.SendHeader(AMsg: TIdMessage); var LHeaders: TIdHeaderList; begin LHeaders ...
- 51nod 1031 骨牌覆盖
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 在2*N的一个长方形方格中,用一个1*2的骨牌排满方格. 问有多少种不同的排列方法. 例如: ...
- feign 负载均衡熔断器
feign:和zuul配合进行负载均衡. 注解的含义: @EnableDiscoveryClient 声明它是一个资源服务端,即可以通过某些接口调用一些资源: @EnableFeignClients ...
- [整理] webpack+vuecli打包生成资源相对引用路径与背景图片的正确引用
webpack+vuecli打包生成资源相对引用路径与背景图片的正确引用 https://www.cnblogs.com/moqiutao/p/7496718.html
- 安装 Zend Studio 报错:0x80070666
出现 0x80070666 报错时 查看日志文件,发现调用VC14(即:Microsoft Visual C++ 2015 Redistributable)时,出错返回0x666 先卸载原有的VC14 ...
- regular expression matching DP
这个题目,我从前天晚上(8月6号晚上)调试到现在(8月8号16:21),太心酸了,不好好总结一下,就太对不起自己了! 这是题目: Implement regular expression matchi ...