8 条题解

  • 3
    @ 2022-3-26 11:21:52
    #include <queue>
    #include <math.h>
    #include <stack>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define LL long long
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    void f(int n , char A , char B , char C)
    {
    	if(n == 0)
    		return ;
    	f( n-1 , A , C , B);
    	cout << "Move " << A <<" to "<<C<<endl;
    	f(n-1 , B , A,C);
    
    }
    int main()
    {
    	int n ;
    	cin >> n;
    	cout << pow(2,n) - 1 << endl;
    	f(n,'A' , 'B'  , 'C');
    	return 0;
    }
    
    • 2
      @ 2021-11-30 17:38:16
      n = int(input())
      print(2**n - 1)
      def move(n, a, b, c):
          if n ==1:
              print("Move",a,"to",c)
              return
          move(n-1, a, c, b)
          print("Move",a,"to",c)
          move(n-1, b, a, c)
      move(n, 'A', 'B', 'C')
      
      • 2
        @ 2021-11-27 20:52:19
        /*****************************************
        备注:
        ******************************************/
        #include <queue>
        #include <math.h>
        #include <stack>
        #include <stdio.h>
        #include <iostream>
        #include <vector>
        #include <iomanip>
        #include <string.h>
        #include <algorithm>
        using namespace std;
        #define LL long long
        const int N = 1e5 + 10;
        const int INF = 0x3f3f3f3f;
        void f(int n , char a , char b , char c)
        {
        	if(n == 0)
        		return ;
        	f( n-1 , a , c , b);
        	cout << "Move " << a <<" to "<<c<<endl;
        	f(n-1 , b , a,c);
        
        }
        int main()
        {
        	int n ;
        	cin >> n;
        	cout << pow(2,n) - 1 << endl;
        	f(n,'A' , 'B'  , 'C');
        	return 0;
        }
        
        • 1
          @ 2023-6-5 17:41:16
          #include <queue>
          #include <math.h>
          #include <stack>
          #include <vector>
          #include <stdio.h>
          #include <iostream>
          #include <vector>
          #include <iomanip>
          #include <string.h>
          #include<cstring>
          #include <algorithm>
          #define LL long long
          const int N = 1e2 + 10;
          const int INF = 0x3f3f3f3f;
          using namespace std;
          int n ;
          void f(int n , char A , char B ,char C )
          {
          	if( n == 0 )
          	{
          		return; 
          	}
          	f( n - 1 , A , C , B );
          	cout << "Move " << A <<" to " << C << endl ;
          	f( n - 1 , B , A , C );
           } 
          int main()
          {
          	cin >> n ;
          	cout << pow(2,n) - 1 << endl ;
          	f( n , 'A' , 'B' , 'C' ); 
          	return 0;
          }
          
          
          • 1
            @ 2023-5-1 15:56:35
            #include<algorithm>
            #include<cmath>
            using namespace std;
            void h(int n,char a, char b, char c){
            	if (n==1){
            		cout << "Move"<<" " << a << " " <<"to" <<" " <<c << endl;
            	}
            	else {
            		h(n-1,a,c,b);
            		h(1,a,b,c );
            		h(n-1,b,a,c);
            	}
            	
            }
            
            int main(){
            	int n;
            	cin >> n;
            	cout << pow(2 , n)-1 << endl;
            	h(n,'A','B','C');
            	return 0;
            }
            
            • 1
              @ 2022-4-17 15:07:46
              #include <queue>
              #include <math.h>
              #include <stack>
              #include <stdio.h>
              #include <iostream>
              #include <vector>
              #include <iomanip>
              #include <string.h>
              #include <algorithm>
              using namespace std;
              #define LL long long
              const int N = 1e5 + 10;
              const int INF = 0x3f3f3f3f;
              void f(int n , char A , char B , char C)
              {
              	if(n == 0)
              		return ;
              	f( n-1 , A , C , B);
              	cout << "Move " << A <<" to "<<C<<endl;
              	f(n-1 , B , A,C);
              
              }
              int main()
              {
              	int n ;
              	cin >> n;
              	cout << pow(2,n) - 1 << endl;
              	f(n,'A' , 'B'  , 'C');
              	return 0;
              }
              
              • 0
                @ 2023-5-1 15:56:19

                #include<iostream> #include<algorithm> #include<cmath> using namespace std; void h(int n,char a, char b, char c){ if (n==1){ cout << "Move"<<" " << a << " " <<"to" <<" " <<c << endl; } else { h(n-1,a,c,b); h(1,a,b,c ); h(n-1,b,a,c); }

                }

                int main(){ int n; cin >> n; cout << pow(2 , n)-1 << endl; h(n,'A','B','C'); return 0; }//非常简单

                • 0

                  #include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; void f(int n , char A , char B , char C) { if(n == 0) return ; f( n-1 , A , C , B); cout << "Move " << A <<" to "<<C<<endl; f(n-1 , B , A,C);

                  } int main() { int n ; cin >> n; cout << pow(2,n) - 1 << endl; f(n,'A' , 'B' , 'C'); return 0; }

                  • 1

                  信息

                  ID
                  1234
                  时间
                  1000ms
                  内存
                  256MiB
                  难度
                  5
                  标签
                  递交数
                  342
                  已通过
                  137
                  上传者