top1编程
← 返回题目
题解

【基础】杰克的小牛

1 条题解

  • 0
    @ 2026-7-29 0:19:36
    #include <cstdio>
    #include <iostream>
    #define for1( i , a , b ) for( int i = a ; i <= b ; i++ )
    using namespace std ;
    
    class Jack
    {
    	public:
    		void play() ;
    	protected:
    		int n , a , f[ 55 ];
    		
    } ;
    void Jack::play()
    {
    	//freopen( "in.txt" , "r" , stdin ) ;
    	//freopen( "out.txt" , "w" , stdout ) ;
    	f[ 1 ] = f[ 2 ] = f[ 3 ] = 1 ;
    	for1( i , 4 , 50 ) f[ i ] = f[ i - 1 ] + f[ i - 3 ] ;
    	scanf( "%d" , &n ) ;
    	while( n-- ) {
    		scanf( "%d" , &a ) ;
    		printf( "%d&#92;n" , f[ a ] ) ;
    	}
    }
    int main()
    {
    	Jack J ;
    	J.play() ;
    	return 0 ;
    }
    
    • 1