HDU 1165 Eddy's research II

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 1165 Eddy's research II相关的知识,希望对你有一定的参考价值。

Eddy‘s research II

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3970    Accepted Submission(s): 1459


Problem Description
As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other hand, the dramatic fast increasing pace of the function caused the value of Ackermann function hard to calcuate.

Ackermann function can be defined recursively as follows:
技术分享

Now Eddy Gives you two numbers: m and n, your task is to compute the value of A(m,n) .This is so easy problem,If you slove this problem,you will receive a prize(Eddy will invite you to hdu restaurant to have supper).
 

 

Input
Each line of the input will have two integers, namely m, n, where 0 < m < =3.
Note that when m<3, n can be any integer less than 1000000, while m=3, the value of n is restricted within 24.
Input is terminated by end of file.
 

 

Output
For each value of m,n, print out the value of A(m,n).
 

 

Sample Input
1 3
2 4
 

 

Sample Output
5
11
 
 
 
解析:推公式。
当m == 0时,A(m,n) = n+1;
当m == 1时,A(m,n) = n+2;
当m == 2时,A(m,n) = 2*n+3;
当m == 3时,A(m,n) = 2n+3-3.(计算2n+3时,可用位运算优化)
 
 
 
 1 #include <cstdio>
 2 
 3 int main()
 4 {
 5     int m,n;
 6     while(~scanf("%d%d",&m,&n)){
 7         if(m == 0)
 8             printf("%d\n",n+1);
 9         else if(m == 1)
10             printf("%d\n",n+2);
11         else if(m == 2)
12             printf("%d\n",2*n+3);
13         else
14             printf("%d\n",(1<<(n+3))-3);
15     }
16     return 0;
17 }

 

以上是关于HDU 1165 Eddy's research II的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1165 Eddy's research II(给出递归公式,然后找规律)

HDU-1165-Eddy&#39;s research II

HDU 1163 Eddy's digital Roots

hdu 1162 Eddy's picture (prim)

HDU1161 Eddy&#39;s mistakes

Hdu 1163 Eddy's digital Roots