猴子吃桃子
This commit is contained in:
parent
2d95dfd953
commit
21eb082bc3
|
@ -0,0 +1,20 @@
|
|||
# 猴子吃桃子
|
||||
|
||||
[问题描述]
|
||||
|
||||
教学案例,必须使用递归函数完成求解!
|
||||
|
||||
猴子吃桃子问题:猴子第一天摘下若干个桃子,当即吃了一半还不过瘾,又多吃了一个;第二天又将剩下的桃子吃掉一半又多吃了一个;以后每天早上都吃了前一天剩下的一半零一个。到了第n天想再吃时,见只剩下一个桃子,求第一天共摘了多少个桃子?
|
||||
1 <= n <= 50
|
||||
|
||||
[输入格式]
|
||||
一个整数值n。
|
||||
|
||||
[输出格式]
|
||||
第一天的桃子总数量。
|
||||
|
||||
[输入样例]
|
||||
3
|
||||
|
||||
[输出样例]
|
||||
10
|
|
@ -0,0 +1 @@
|
|||
#
|
|
@ -0,0 +1,15 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
long long zhao(long long n){
|
||||
if(n==1){
|
||||
return 1;
|
||||
}else{
|
||||
return zhao(n-1)*2+2;
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
cout<<zhao(n);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
3
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1 @@
|
|||
50
|
|
@ -0,0 +1,18 @@
|
|||
## z:\Chao\src\1667_houtao\test\in.txt
|
||||
2020/04/30 ÖÜËÄ 18:09:08.04
|
||||
10
|
||||
-----------------------------------------------
|
||||
Process exited after 170 ms with return value 0
|
||||
|
||||
## z:\Chao\src\1667_houtao\test\in2.txt
|
||||
2020/04/30 ÖÜËÄ 18:09:08.04
|
||||
1
|
||||
-----------------------------------------------
|
||||
Process exited after 80 ms with return value 0
|
||||
|
||||
## z:\Chao\src\1667_houtao\test\in3.txt
|
||||
2020/04/30 ÖÜËÄ 18:09:08.04
|
||||
1688849860263934
|
||||
-----------------------------------------------
|
||||
Process exited after 90 ms with return value 0
|
||||
|
Loading…
Reference in New Issue