http://acm.hdu.edu.cn/showproblem.php?pid=2717
Water search ...
1#include <stdio.h>2#include <math.h>3#include <string.h>4#include <stdlib.h>5#include <iostream>6#include <queue>7 using namespacestd;8 structstu{9 intx;Ten intT; One }abc,q; A intn,k; - intvis[100005]; - voidBFS () the { -queue<structStu>p; - P.push (ABC); - while(!p.empty ()) + { -Abc=P.front (); + P.pop (); A if(abc.x==k) at { -printf"%d\n", abc.t); - return ; - } -q.x=abc.x-1; - if(q.x>=0&&q.x<=100000&&!vis[q.x]) in { -q.t=abc.t+1; tovis[q.x]=1; + P.push (q); - } theq.x=abc.x+1; * if(q.x>=0&&q.x<=100000&&!vis[q.x]) $ {Panax Notoginsengq.t=abc.t+1; -vis[q.x]=1; the P.push (q); + } Aq.x=abc.x*2; the if(q.x>=0&&q.x<=100000&&!vis[q.x]) + { -q.t=abc.t+1; $vis[q.x]=1; $ P.push (q); - } - } the } - Wuyi intMain () the { - //freopen ("In.txt", "R", stdin); Wu while(~SCANF ("%d%d",&n,&k)) - { Aboutmemset (Vis,0,sizeof(Vis)); $abc.x=N; -abc.t=0; -vis[n]=1; - BFS (); A } + return 0; the}
hdu2717 Catch that Cow