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 ...
随机推荐
- HTML 5 应用程序缓存(上)
什么是应用程序缓存(Application Cache)?HTML5 引入了应用程序缓存,这意味着 web 应用可进行缓存,并可在没有因特网连接时进行访问. 应用程序缓存为应用带来三个优势: 离线浏览 ...
- Android混淆打包
一.理论知识 ProGuard是一款免费的Java类文件压缩器.优化器和混淆器.它能发现并删除无用类.字段(field).方法和属性值(attribute).它也能优化字节码并删除无用的指令.最后 ...
- java(2)之前往对象村
这次说一说面向对象与面向过程的区别以及面向对象的优点.
- IOS8解决获取位置坐标信息出错(Error Domain=kCLErrorDomain Code=0)(转)
标题:IOS8解决获取位置坐标信息出错(Error Domain=kCLErrorDomain Code=0) 前几天解决了在ios8上无法使用地址位置服务的问题,最近在模拟器上调试发现获取位置坐标信 ...
- cygwin安装
我安装的是cygwin2.5.2,相关下载:https://cygwin.com/setup-x86_64.exe 先安装cygwin,x86_64版本,安装时选择库(gcc-core.gcc-c++ ...
- Codeigniter文件上传类型不匹配错误
Codeigniter的文件上传类方便了我们使用PHP来处理文件上传的操作,使用起来非常简单,如下: $config['upload_path'] = './uploads/'; $config[ ...
- python 中的 try/except/else/finally语句
1.python中try/except/else/finally正常的语句是这样的: try: normal excute block except A: Except A handle except ...
- Example For maven-compiler-plugin
1. Compiling Sources Using A Different JDK The compilerVersion parameter can be used to specify the ...
- 1005. Spell It Right (20)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...
- c# 邮件发送功能
//统一由一个邮箱发送录用通知 string strfrom = "";//发件人邮箱地址 string strpow = "";//邮箱密码 string s ...