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 |
Re:50题纪念In Reply To:50题纪念 Posted by:rudylau at 2008-07-30 13:26:16 > #include<iostream> > using namespace std; > int a[200000],b[100000],c[100000]; > unsigned R,co,N,K,i,j; > void Rudy(int l) > { > co++;i=0; > if(co%2) > for(j=1;j<=l;j++) > { > if(!a[2*b[j]]&&b[j]<=50002){a[2*b[j]]=1;c[++i]=2*b[j];} > if(!a[b[j]-1]&&b[j]>=2){a[b[j]-1]=1;c[++i]=b[j]-1;} > if(!a[b[j]+1]&&b[j]<=100002){a[b[j]+1]=1;c[++i]=b[j]+1;} > } > else > for(j=1;j<=l;j++) > { > if(!a[2*c[j]]&&c[j]<=50002){a[2*c[j]]=1;b[++i]=2*c[j];} > if(!a[c[j]-1]&&c[j]>=2){a[c[j]-1]=1;b[++i]=c[j]-1;} > if(!a[c[j]+1]&&c[j]<=100002){a[c[j]+1]=1;b[++i]=c[j]+1;} > } > if(a[K]){cout<<co<<endl;return;} > Rudy(i); > } > int main() > { > cin>>N>>K; > if(N>=K)cout<<N-K<<endl; > else{b[1]=N;Rudy(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