poj3278
来源:互联网 发布:win10跟windows server 编辑:程序博客网 时间:2024/06/05 16:05
g++ wa了,c++ ac了,渣渣不懂,这道题。。。
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <stdlib.h>
using namespace std;
bool mapp[100005];
int walk[100005];
int f,l;
int bfs()
{
memset(mapp,0,sizeof(mapp));
queue<int>q;
q.push(f);
mapp[f]=1;
walk[f]=0;
while(!q.empty())
{
int tmp=q.front();
q.pop();
for(int i=0;i<3;i++)
{
int next;
if(i==0)next=tmp-1;
else if(i==1)next=tmp+1;
else next=tmp*2;
if(next<0||next>100000||mapp[next])continue;
if(!mapp[next])
{
q.push(next);
mapp[next]=1;
walk[next]=walk[tmp]+1;
}
if(next==l)return walk[next];
}
}
}
int main()
{
cin>>f>>l;
if(f>=l)cout<<f-l<<endl;
else cout<<bfs()<<endl;
return 0;
}
- POJ3278
- POJ3278
- POJ3278
- poj3278
- poj3278
- poj3278
- POJ3278
- POJ3278
- poj3278
- poj3278
- poj3278
- POJ3278
- poj3278
- poj3278
- poj3278
- poj3278
- POJ3278
- POJ3278
- C语言实现raw格式图像的读入和存取
- String的hashCode分析
- 分组转发算法和距离向量算法
- Java的内存分配
- spring mvc各种参数在jsp和action之间的传递
- poj3278
- 在C/C++代码中使用SSE等指令集的指令(2)参考手册
- 修改frame值中的某一个属性的值
- Python编写微信打飞机小游戏(四)
- ontouchstart实现手机触屏中的hover成效
- Android项目Tab类型主界面大总结 Fragment+TabPageIndicator+ViewPager
- gdb 调试多进程
- 在C/C++代码中使用SSE等指令集的指令(3)SSE指令集基础
- Eclipse svn插件的使用