递归函数(Recursion of function)

hduacm2044

   
     
#include " iostream "
#include
< cstdio >
using namespace std;
__int64 m[
51 ];
int main()
{
int n,i,a,b;

m[
1 ] = 1 ;m[ 2 ] = 1 ;
for (i = 3 ;i <= 50 ;i ++ )
{
m[i]
= m[i - 2 ] + m[i - 1 ];

}

scanf(
" %d " , & n);
while (n -- )
{
scanf(
" %d %d " , & a, & b);
if (a > 0 && a < b && b < 50 )
printf(
" %I64d\n " ,m[b - a + 1 ]);


}
return 0 ;
}

 

hduacm2045
   
     
1 #include " iostream "
2   using namespace std;
3   int main()
4 {
5 int n,i;
6 __int64 a[ 51 ] = { 0 , 3 , 6 , 6 };
7 while (scanf( " %d " , & n) != EOF)
8 {
9
10 if (n >= 4 && n <= 50 )
11 {
12 for (i = 4 ;i <= n;i ++ )
13 a[i] = a[i - 1 ] + 2 * a[i - 2 ];
14 }
15 printf( " %I64d\n " ,a[n]);
16 }
17 return 0 ;
18 }

 

hduacm2046
   
     
1 #include " iostream "
2   using namespace std;
3   int main()
4 {
5 __int64 a[ 55 ] = { 0 , 1 , 2 };
6 int n,i;
7
8 for (i = 3 ;i < 55 ;i ++ )
9 a[i] = a[i - 1 ] + a[i - 2 ];
10 while (cin >> n && n != 0 )
11 {
12 if (n > 0 && n <= 50 )
13 printf( " %I64d\n " ,a[n]);
14 }
15 return 0 ;
16 }
17

 

hduacm2050
   
     
1 #include " iostream "
2 using namespace std;
3 int main()
4 {
5 int i, c,a[ 1000 ],sum;
6 while (cin >> c)
7 {
8 for (i = 0 ;i < c;i ++ )
9 cin >> a[i];
10 for (i = 0 ;i < c;i ++ )
11 if (a[i] > 0 && a[i] <= 10000 )
12 {
13 sum = 2 * a[i] * a[i] - a[i] + 1 ;
14 cout << sum << endl;
15 }
16 }
17 return 0 ;
18 }

 

你可能感兴趣的:(function)