poj 3278 Catch That Cow (bfs 搜索)
一直很晕,用c++16Ms过,用G++WA!!!!!!!!
http://poj.org/problem?id=3278
#include<stdio.h>
#include<string.h>
#define N 100000
int n,k,vis[N];
struct node
{int step;int num;
}p[N*10];
int bfs()
{memset(vis,0,sizeof(vis));int head=0,tail=0;p[head].num=n;p[head].step=0;vis[n]=1;tail++;while(head<tail){int l=p[head].num;if(l==k)return p[head].step;if(p[head].num+1<=N&&!vis[p[head].num+1]){p[tail].num=p[head].num+1;vis[p[head].num+1]=1;p[tail].step=p[head].step+1;tail++;}if(p[head].num-1>=0&&!vis[p[head].num-1]){p[tail].num=p[head].num-1;vis[p[head].num-1]=1;p[tail].step=p[head].step+1;tail++;}if(p[head].num*2<=N&&!vis[p[head].num*2]){p[tail].num=p[head].num*2;vis[p[head].num*2]=1;p[tail].step=p[head].step+1;tail++;}head++;}return 0;
}
int main()
{while(scanf("%d%d",&n,&k)!=EOF){int ans= bfs();printf("%d\n",ans);}
}
转载于:https://www.cnblogs.com/acSzz/archive/2012/03/03/2378640.html
poj 3278 Catch That Cow (bfs 搜索)相关推荐
- POJ 3278 Catch That Cow BFS
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32071 Accepted: 9866 D ...
- 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 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- BFS POJ 3278 Catch That Cow
题目传送门 1 /* 2 BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 3 */ 4 #include <cstdio> 5 #include <iostrea ...
- POJ 3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30924 Accepted: 9536 D ...
- POJ 3278 Catch That Cow(BFS)
题目网址:http://poj.org/problem?id=3278 题目: Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Tot ...
- bfs+dfs分析----poj 3278 Catch That Cow
题目详情 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 115430 Accepted: ...
- POJ 3287 Catch That Cow(bfs)
看懂意思就很简单了,给你一个数,每次只能加一或者减一或者乘2,问最少几次才能变成另一个数,就是一个简单的bfs过程,看代码吧. AC代码: #include <iostream> ...
- poj 3278 Catch That Cow(广搜)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45087 Accepted: 14116 ...
- POJ 3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35043 Accepted: 10800 ...
最新文章
- asp.net 2.0小TIPS两则
- 怎样将jsonObject类型转换为date数据类型?
- python怎样定义一个数组_Python创建数组
- JavaScript 中创建三种消息框:警告框、确认框、提示框
- JavaScript自定义浏览器滚动条兼容IE、 火狐和chrome
- .NET 运行时设置
- Fisher–Yates shuffle 算法
- ***PHP Notice: Undefined index: ..问题的解决方法
- 自学python好找工作么-学习python后好找工作吗
- android调用本地js文件上传,利用node.js android 实现文件上传
- 计算机硬盘哒哒响,教你轻松解决硬盘异响(咔咔或者嗒嗒声)
- Workbench网格分块分区划分 扫面、节点控制网格数的应用
- Enterprise Architect安装使用
- 从阿里、华为、海尔的崛起看:财务生产力可以有多强
- 前期易语言编程作品收录|DKP系统|
- 深圳java程序员培训班哪里最好,深圳java程序员培训学费(学习Java要不要报班)
- yys opencv自动图片识别 学习交流
- Hadoop2.x与Hadoop3.x的默认端口变化
- 第十五天 13-linux防火墙
- git基础之切换分支