猴子吃桃子

This commit is contained in:
James 2020-04-30 18:11:05 +08:00
parent 2d95dfd953
commit 21eb082bc3
8 changed files with 57 additions and 0 deletions

20
1667_houtao/Readme.md Normal file
View File

@ -0,0 +1,20 @@
# 猴子吃桃子
[问题描述]
教学案例,必须使用递归函数完成求解!
  猴子吃桃子问题猴子第一天摘下若干个桃子当即吃了一半还不过瘾又多吃了一个第二天又将剩下的桃子吃掉一半又多吃了一个以后每天早上都吃了前一天剩下的一半零一个。到了第n天想再吃时见只剩下一个桃子求第一天共摘了多少个桃子
  1 <= n <= 50
[输入格式]
  一个整数值n。
[输出格式]
  第一天的桃子总数量。
[输入样例]
3
[输出样例]
10

View File

@ -0,0 +1 @@
#

15
1667_houtao/main.cpp Normal file
View File

@ -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);
}

BIN
1667_houtao/main.exe Normal file

Binary file not shown.

1
1667_houtao/test/in.txt Normal file
View File

@ -0,0 +1 @@
3

1
1667_houtao/test/in2.txt Normal file
View File

@ -0,0 +1 @@
1

1
1667_houtao/test/in3.txt Normal file
View File

@ -0,0 +1 @@
50

18
1667_houtao/test/out.txt Normal file
View File

@ -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