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 |
菜鸟求教 自己测得都对~~#include <iostream> #include <cstdio> using namespace std; int n,k; int dui[1000001],step[1000001]; void init() { scanf("%d %d",&n,&k); } void solve() { int head=0,tail=1; dui[head]=n; while(head!=tail) { if(dui[head]==k) { printf("%d",step[head]); break; } if(dui[head]<=k) { dui[tail]=dui[head]*2; step[tail]=step[head]+1; tail=(tail+1)%1000000; } dui[tail]=dui[head]-1; step[tail]=step[head]+1; tail=(tail+1)%1000000; if(dui[head]<=k) { dui[tail]=dui[head]+1; step[tail]=step[head]+1; tail=(tail+1)%1000000; } head=(head+1)%1000000; } } int main() { init(); solve(); return(0); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator