POJ 3278 Catch That Cow
来源:互联网 发布:java 判断object 类型 编辑:程序博客网 时间:2024/06/04 17:54
注意x等于0的时候就不要减一了,同样x*2大于10W也不行
#include <iostream>#include <cstdio>#include <memory.h>#include <queue>using namespace std;const int maxn=100010;bool vis[maxn];int x,k;struct state{int x,t;state(int xx=0,int tt=0):x(xx),t(tt){}};int bfs(int s){queue<state>q;q.push(state(s,0));vis[s]=1;while (q.size()){state t=q.front();q.pop();if(t.x==k)return t.t;int nx=t.x+1;if(t.x<k&&!vis[nx]){//如果当前x比k大 那没有必要加1vis[nx]=1;q.push(state(nx,t.t+1));}nx=t.x-1;if(nx>=0&&!vis[nx]){//边界vis[nx]=1;q.push(state(nx,t.t+1));}if(t.x<k&&t.x*2<maxn&&!vis[t.x*2]){//如果当前x比k大,没必要乘2vis[t.x*2]=1;q.push(state(t.x*2,t.t+1));}}}int main(){while (scanf("%d%d",&x,&k)==2){memset(vis,0,maxn);printf("%d\n",bfs(x));}return 0;}
- poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- poj 3278 catch that cow
- poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- Poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- POJ 3278 Catch That Cow
- POJ 3278 Catch That Cow
- poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- poj 3278 Catch That Cow
- poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- POJ 3278 - Catch That Cow
- POJ 3278 Catch That Cow
- POJ 3278 Catch That Cow
- POJ-3278-Catch That Cow
- heike
- css选择器的优先级别和如何编写简洁、高效的css
- asp.net的<% %>总结
- ubuntu 查看系统信息
- QT里用QML写的Android程序关于设置横屏的方法
- POJ 3278 Catch That Cow
- 大话设计模式总结2---设计模式六原则
- n的阶乘最后一个非0的数
- android开发项目的各个目录的说明
- unity的#pragma strict,#pragma downcast等指令分享
- <meta http-equiv=...> 的功能
- python利用K均值做聚类,判断中国足球第几流
- 提高语言组织能力
- 【黑马程序员】分布式事务TransactionScope(学习笔记)