A. Transformation: from A to B
time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
题意:
有两种变换方式:
(1)x*10+1
(2)x*2
问a能否经过两种变换转换成b
如果b是奇数,则必是由(1)方式转换而来,若为偶数则必是(2)转换而来。
附AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int c[100010]; 5 6 int main(){ 7 int a,b; 8 cin>>a>>b; 9 int ans=1; 10 c[0]=b; 11 int flag=1; 12 while(a<b){ 13 if((b-1)%10==0){ 14 b=(b-1)/10; 15 c[ans++]=b; 16 } 17 else if(b%2==0){ 18 b/=2; 19 c[ans++]=b; 20 } 21 else{ 22 flag=0; 23 break; 24 } 25 } 26 if(flag==0){ 27 cout<<"NO"<<endl; 28 } 29 else if(a==b){ 30 cout<<"YES"<<endl; 31 cout<<ans<<endl; 32 for(int i=ans-1;i>=0;i--){ 33 cout<<c[i]<<" "; 34 } 35 } 36 else{ 37 cout<<"NO"<<endl; 38 } 39 return 0; 40 }