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 ...
随机推荐
- sql子查询的例子
1.单行子查询 select ename,deptno,sal from emp where deptno=(select deptno from dept ...
- BBS项目总结
数据库(Oracle): BBSUserid:主键username:用户名password:密码pic:头像 blobpagenum:每个人分页喜好数量,每页显示多少行 Article :ID:主键, ...
- CSS3实现单行、多行文本溢出(省略号的形式出现)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Android(java)学习笔记168:Activity 4 种启动模式
1. 任务栈(task stack): 任务栈 是用来记录用户操作的行为,维护一个用户体验. 一个应用程序一般都是由多个activity组成的. 任务栈(task stack)记录存放用户开启的act ...
- DROP FUNCTION - 删除一个函数
SYNOPSIS DROP FUNCTION name ( [ type [, ...] ] ) [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP FUNCTION ...
- window.onload和DOMContentLoaded的区别
一.何时触发这两个事件? 1.当 onload 事件触发时,页面上所有的DOM,样式表,脚本,图片,flash都已经加载完成了. 2.当 DOMContentLoaded 事件触发时,仅当DOM加载完 ...
- Java练习demo 20190402 优惠券扣减
实体类: package org.jimmy.autosearch2019.pojo; import java.math.BigDecimal; public class TestEntity2019 ...
- 有n个整数,使其前面各数顺序向后移n-m个位置,最后m个数变成最前面的m个数
题目:有n个整数,使其前面各数顺序向后移n-m个位置,最后m个数变成最前面的m个数 public class 第三十六题数组向后移m个位置 { public static void main(Stri ...
- 解决mysql - 1577 问题
背景:通过navicat连接mysql使用events时报如下错误 登录mysql查询event mysql> use zhk4; Database changed mysql> show ...
- 数据结构( Pyhon 语言描述 ) — — 第4章:数据和链表结构
数据结构是表示一个集合中包含的数据的一个对象 数组数据结构 数组是一个数据结构 支持按照位置对某一项的随机访问,且这种访问的时间是常数 在创建数组时,给定了用于存储数据的位置的一个数目,并且数组的长度 ...