Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
3278 已解决#include<iostream> using namespace std; struct xt { int N,t; }a[100001]; int main() { int K,i,j,k1,used[100001]; while(scanf("%d%d",&a[0].N,&K)!=EOF) { if(a[0].N==K) printf("0\n"); else { memset(used,0,sizeof(used)); i=0; j=1; while(i<j) { k1=a[i].N+1; if(k1==K) break; if(k1<100001&&!used[k1]) { used[k1]=1; a[j].N=k1; a[j++].t=a[i].t+1; } k1=a[i].N-1; if(k1==K) break; if(k1>=0&&!used[k1]) { used[k1]=1; a[j].N=k1; a[j++].t=a[i].t+1; } k1=2*a[i].N; if(k1==K) break; if(k1<100001&&!used[k1]) { used[k1]=1; a[j].N=k1; a[j++].t=a[i].t+1; } i++; } printf("%d\n",a[i].t+1); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator