swear01

ZeroJudge b190

Sep 20th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4.  
  5.  
  6. using namespace std ;
  7. void give(int from , int to , int k) ;
  8. void tar(int from , int to , int k) ;
  9. void tarplace(int from ,int  to ,int  k) ;
  10.  
  11.  
  12. int count=0 ;
  13. int a=1,b=2 ,c=3 ;
  14.  
  15. void give(int from , int to , int k){
  16.     cout << "ring " << k << " : " << char('a'- 1+ from ) << " -> " << char('a'-1+to)  << "\n" ;
  17.     count++ ;
  18. }
  19.  
  20. void tar(int from , int to , int k){
  21.     int last ;
  22.     last = 6- from - to ;
  23.     if (k >1){
  24.         tar(from , last , k-1) ;
  25.         give( from , to ,  k) ;
  26.         tar(last,to , k-1) ;
  27.     }
  28.     else give( from , to ,  k) ;
  29.  
  30.  
  31. }
  32. /*
  33. 1.整疊少一送到last
  34. 2.底盤送到to
  35. 3.last留兩個 (k-3層)回去from
  36. 4.留下的上面那一個去to
  37. */
  38.  
  39. void tarplace(int from ,int  to ,int  k){
  40.     int last = 6- from - to;
  41.     if (k >2){
  42.         tar(from , last , k-1) ;
  43.        
  44.         give(from , to , k) ;
  45.        
  46.         if (k >3 ) tar(last , from , k-3) ;
  47.        
  48.         give(last , to , k-2) ;
  49.        
  50.         tarplace(from,char('a'+4-to),k-3) ;
  51.     }
  52.    
  53.     else if (k==2){
  54.         give(from , last , k-1) ;
  55.         give(from , to , k) ;  
  56.     }  
  57.     else if (k==1) give(from , to , k) ;    
  58. }
  59. /*
  60. void tareven(int from ,int  to ,int  k){
  61.     int last = 6- from - to;
  62.  
  63.     tar(from , last , k-1) ;
  64.    
  65.     cout << "ring " << k << " : " << char('a'-1+from) << " -> " << char('a'-1+to)   << endl ;
  66.     count++ ;
  67.  
  68.     tarodd(last,to , k-1) ;
  69. }
  70.  
  71. void tarodd(int from,int to,int k){
  72.     int last ;
  73.     last = 6- from - to ;
  74.     if (k > 1){
  75.     tar(from , last , k-1) ;
  76.    
  77.     cout << "ring " << k << " : " << char('a'-1+from) << " -> " << char('a'-1+to)  << endl ;
  78.     count++ ;
  79.    
  80.     tareven(last,to , k-1) ;
  81.     }
  82.     else cout << "ring " << k << " : " << char('a'-1+from) << " -> " << char('a'-1+to)  << endl ,count++ ;
  83.    
  84.    
  85. }
  86. */
  87. int main() {
  88.     ios::sync_with_stdio(false);
  89.     int n= 0 ;
  90.     cin >> n ;
  91.     tarplace(a,c,n) ;
  92.   cout << "共移動了 " << count << " 步" << "\n" ;
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment