POJ3278 Catch That Cow
来源:互联网 发布:淘宝客服模板大小 编辑:程序博客网 时间:2024/06/06 07:36
#include<iostream>#include<cstring>#include<queue>using namespace std;int N,K;//农夫N,牛Kconst int MAXN=100000;int visited[MAXN+10];//判重标记,visited[i]=1 表示i已经扩展过struct Step{ int x;//位置 int steps;//到达x所需的步数 Step(int xx,int s):x(xx),steps(s){}};queue<Step> q;//Open表int main(){//bfs cin>>N>>K; memset(visited,0,sizeof(visited));//全部标记为未扩展 q.push(Step(N,0)); visited[N]=1;//标记为已访问 while(!q.empty()){ Step s=q.front(); if(s.x==K){//找到目标 cout<<s.steps<<endl; return 0; }else{ if(s.x-1>=0&&!visited[s.x-1]){//-1扩展 q.push(Step(s.x-1,s.steps+1)); visited[s.x-1]=1; } if(s.x+1<=MAXN&&!visited[s.x+1]){//+1扩展 q.push(Step(s.x+1,s.steps+1)); visited[s.x+1]=1; } if(s.x*2<=MAXN&&!visited[s.x*2]){//乘2扩展 q.push(Step(s.x*2,s.steps+1)); visited[s.x*2]=1; } q.pop();//扩展完后出队列 } } return 0;}
0 0
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278 - Catch That Cow
- POJ3278 Catch That Cow
- POJ3278--Catch That Cow
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278--Catch That Cow
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- POJ3278,Catch That Cow
- poj3278--Catch That Cow
- POJ3278---Catch That Cow
- poj3278 Catch That Cow
- poj3278 catch that cow
- Catch That Cow poj3278
- Catch That Cow--poj3278
- Android性能专项测试之Network monitor
- 五、智力题
- 黑马程序——抽象类和接口
- linux
- CURL GET POST
- POJ3278 Catch That Cow
- java中String s="abc"及String s=new String("abc")详解
- linux环境下修改环境变量的几点总结
- Map遍历的方法
- Android性能专项测试之GPU Monitor
- 迷宫算法以及图形化android显示
- 分享一个不错的mysql语句
- snmp 表对象 的自动编译
- 016redis3.0集群简介