一直很晕,用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 搜索)相关推荐

  1. POJ 3278 Catch That Cow BFS

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 32071   Accepted: 9866 D ...

  2. poj 3278 catch that cow BFS(基础水)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 61826   Accepted: 19329 ...

  3. POJ - 3278 Catch That Cow 简单搜索

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

  4. BFS POJ 3278 Catch That Cow

    题目传送门 1 /* 2 BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 3 */ 4 #include <cstdio> 5 #include <iostrea ...

  5. POJ 3278 Catch That Cow

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 30924   Accepted: 9536 D ...

  6. POJ 3278 Catch That Cow(BFS)

    题目网址:http://poj.org/problem?id=3278 题目: Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Tot ...

  7. bfs+dfs分析----poj 3278 Catch That Cow

    题目详情 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 115430   Accepted:  ...

  8. POJ 3287 Catch That Cow(bfs)

          看懂意思就很简单了,给你一个数,每次只能加一或者减一或者乘2,问最少几次才能变成另一个数,就是一个简单的bfs过程,看代码吧. AC代码: #include <iostream> ...

  9. poj 3278 Catch That Cow(广搜)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 45087   Accepted: 14116 ...

  10. POJ 3278 Catch That Cow

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 35043   Accepted: 10800 ...

最新文章

  1. asp.net 2.0小TIPS两则
  2. 怎样将jsonObject类型转换为date数据类型?
  3. python怎样定义一个数组_Python创建数组
  4. JavaScript 中创建三种消息框:警告框、确认框、提示框
  5. JavaScript自定义浏览器滚动条兼容IE、 火狐和chrome
  6. .NET 运行时设置
  7. Fisher–Yates shuffle 算法
  8. ***PHP Notice: Undefined index: ..问题的解决方法
  9. 自学python好找工作么-学习python后好找工作吗
  10. android调用本地js文件上传,利用node.js android 实现文件上传
  11. 计算机硬盘哒哒响,教你轻松解决硬盘异响(咔咔或者嗒嗒声)
  12. Workbench网格分块分区划分 扫面、节点控制网格数的应用
  13. Enterprise Architect安装使用
  14. 从阿里、华为、海尔的崛起看:财务生产力可以有多强
  15. 前期易语言编程作品收录|DKP系统|
  16. 深圳java程序员培训班哪里最好,深圳java程序员培训学费(学习Java要不要报班)
  17. yys opencv自动图片识别 学习交流
  18. Hadoop2.x与Hadoop3.x的默认端口变化
  19. 第十五天 13-linux防火墙
  20. git基础之切换分支

热门文章

  1. 一、RequireHttps
  2. C++自己实现一个String类
  3. webpack入门1
  4. Guava Cache本地缓存
  5. 在vue 中使用Stylus
  6. 数组的声明、创建、初始化
  7. VC++6.0选择打开文件命令时停止工作解决方法
  8. ADT下载地址整理(转)
  9. awk substr()函数
  10. Vue学习笔记(五)