Virtual Judge POJ 3278 Catch That Cow
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
const int maxn =;
using namespace std;
int n,m;
struct data {
int x,step;
} p;
int vis[];
void bfs() {
memset(vis,,sizeof(vis)); //重置
queue<data>q; //队列
p.x=n; //起点
p.step=; //起点到起点的距离
q.push(p); //压入队列
vis[n]=; //走过
while(!q.empty()) {
p=q.front();
q.pop();
if(p.x==m) {
printf("%d\n",p.step); //直接输出
return ;
}
data k=p;
if(k.x+<maxn&&!vis[k.x+]) { //尝试前进一步
k.x++; //如果可以,加坐标
vis[k.x]=; //标记走过
k.step++; // 加步数
q.push(k); //新的位置压入队列 }
k=p;
if(k.x->=&&!vis[k.x-]) { //尝试后退一步
k.x--;
vis[k.x]=;
k.step++;
q.push(k);
}
k=p;
if(k.x*<maxn&&!vis[k.x*]) { //尝试传送
k.x*=;
vis[k.x]=;
k.step++;
q.push(k);
}
}
}
int main() {
scanf("%d%d",&n,&m);
bfs();
return ;
}
Virtual Judge 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(简单一维广搜)
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: 80273 Accepted: 25 ...
- 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 ...
随机推荐
- Spark学习之路 (七)Spark 运行流程[转]
Spark中的基本概念 (1)Application:表示你的应用程序 (2)Driver:表示main()函数,创建SparkContext.由SparkContext负责与ClusterManag ...
- openlayers画区域
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- tmp = 2/4;竟然没有发现的
我还纠结着单目运算符和双目运算符和乘除的一些优先级什么事情. #include "common.h" #include <stdio.h> #include <s ...
- VPS性能测试shell工具以及锐速安装
比较熟悉的UnixBench非常耗费资源,需要长时间跑满cpu和IO,很多主机商都深恶痛绝,会做各种限制,其实也代表不了实际使用的业务效果,毕竟真正需要那么多cpu和IO的应用并不多.而网络状况却是大 ...
- POJ2226(二分图建图/最小点覆盖)
题意: 给定m*n的棋盘,有若干只咕咕.希望去掉一部分咕咕使得剩下的咕咕在上下左右四个方向越过咕咕槽的情况下都看不到咕咕. 思路: 建立一个二分图的方法有很多,这里采用xy二分. 假设没有咕咕槽的情况 ...
- nodeJS菜鸟教程笔记
http模块 var http = require('http'); // 引入http模块 var url = require('url'); // 引入url模块 var querystring ...
- UTF-8与GBK的区别
中文解码提示UnicodeDecodeError,UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 0: inv ...
- layer弹出层右上角的关闭按钮怎么没有显示
问题描述:layer弹出层右上角的关闭按钮怎么没有显示,但鼠标移上去又可以点击 解决方式: 这是因为样式中需要一个图标,你的项目中缺少.解决如下:1.下载图标:http://www-x-zi-han- ...
- jenkins Exec exit status not zero. Status [-1]
jenkins是使用ssh连接服务器后,如果使用grep获取进程并kill时,会jenkins Exec exit status not zero. Status [-1],解决办法:在获取进程时,使 ...
- 刷题76. Minimum Window Substring
一.题目说明 题目76. Minimum Window Substring,求字符串S中最小连续字符串,包括字符串T中的所有字符,复杂度要求是O(n).难度是Hard! 二.我的解答 先说我的思路: ...