9 条题解

  • 1
    @ 2025-8-10 21:29:30
    #include<bits/stdc++.h>
    using namespace std;
    int n,ans=1,a[100000];
    void move(int n,char a,char b,char c){
    	if(n==0) return;
    	move(n-1,a,c,b);
    	cout << "Move " << a << " to " << c << "\n";
    	move(n-1,b,a,c);
    }
    int main(){
    	cin >> n;
    	a[1]=1;
    	for(int i=2; i<=n; i++){
    		a[i]=a[i-1]*2+1;
    	}
    	cout << a[n] << "\n";
    	move(n,'A','B','C');
    	return  0;
    }
    
    
    
    • 1
      @ 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;
      }
      
      • 0
        @ 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;
        }
        
        
        • 0
          @ 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;
          }
          
          • 0
            @ 2023-5-1 15:56:19

            #include #include #include 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
              @ 2023-5-1 15:35:59

              #include #include <math.h> #include #include <stdio.h> #include #include #include #include <string.h> #include 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
                @ 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
                  @ 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')
                  
                  • 0
                    @ 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

                    信息

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