1 solutions
-
0
C :
#include<stdio.h> int main() { int i,m,n,a[100]={0,1,1}; scanf("%d",&n); while(n--) { scanf("%d",&m); for(i=3;i<=m;i++) a[i]=a[i-1]+a[i-3]; printf("%d\n",a[m]); } return 0; }
C++ :
#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\n" , f[ a ] ) ; } } int main() { Jack J ; J.play() ; return 0 ; }
- 1
Information
- ID
- 10049
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By