POJ_3278_广搜
来源:互联网 发布:淘宝店铺统计工具 编辑:程序博客网 时间:2024/04/27 20:48
//============================================================================
// Name : POJ_3278.cpp
// Author : tiger
// Version :
// Copyright : 广搜即可
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
struct step
{
int location,steps;
};
#define MAX 200003
bool flag[200005] = {false};
int bfs(step start,int destnation)
{
if(start.location == destnation)
return 0;
queue<step> q;
q.push(start);
flag[start.location] = true;
step next,temp;
while(!q.empty())
{
temp = q.front();
q.pop();
next.steps = temp.steps+1;
//+1
next.location = temp.location+1;
if(next.location == destnation)
return next.steps;
if(next.location <= MAX && !flag[next.location])
{
q.push(next);
flag[next.location] = true;
}
//-1
next.location = temp.location - 1;
if(next.location == destnation)
return next.steps;
if(next.location >=0 && next.location <= MAX && !flag[next.location])
{
q.push(next);
flag[next.location] = true;
}
//*2
next.location = temp.location*2;
if(next.location == destnation)
return next.steps;
if(next.location <= MAX && !flag[next.location])
{
q.push(next);
flag[next.location] = true;
}
}
return 0;
}
int main() {
int n,k;
scanf("%d %d",&n,&k);
step start;
start.location = n;
start.steps = 0;
printf("%d/n",bfs(start,k));
return 0;
}
- POJ_3278_广搜
- POJ_3278_ Catch That Cow _广搜
- 广搜
- 广搜
- 广搜
- 广搜
- 广搜
- 广搜
- 深搜 广搜
- hdu 1026 广搜
- 1242 rescue 广搜
- zoj 1091 广搜。
- POJ3083 广搜&模拟
- poj3278基本广搜
- POJ3414广搜&回溯
- nysit 20 广搜
- 双向广搜
- 双向广搜
- 有关 Form 的一些代码的标准写法
- 英语五种基本句型 及如何区分双宾语和宾语补足语
- 用代码将数据绑定到GridView
- 见到了张孝祥老师..
- UVA 100 The 3n + 1 problem
- POJ_3278_广搜
- Source Insight中文字体设置
- Ajax 总结
- Java5.0垃圾回收性能调优-1、简介,2、Ergonomics工效学[Vange译]
- pku 1017 贪心
- 周邓之旅
- C++字符串
- 电厂ERP管理软件
- CxxTest的环境配置