求大佬发题解

B. 猴子吃桃

Problem ID: 1125

Contest ID: 6030

必做题

时间:1s;空间:64M

问题描述:

编程计算猴子吃桃问题:有一天小猴摘了很多桃子,当即吃了一半,还觉得不过瘾,又多吃了一只;第二天接着吃了剩下的桃子中的一半,仍不过瘾,又多吃了一只;以后每天都吃尚存桃子的一半零一只。到第n天早上就只剩下一只了,问小猴那天共摘了多少只桃子。

输入格式:

输入一行,包含一个整数n。

输出格式:

输出一行,一个整数代表桃子总数。

样例输入:

5

样例输出:

46

约定:

0<=n<=50

3 个赞
 int day=9,x1=0,x2=1;
int main()
{
   
    while(day--)
    {
        x1=(x2+1)*2;
        x2=x1;
    }
    printf("%d\n",x1);
}
5 个赞

好像不行

4 个赞
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, s = 1;
    cin>>n;
    for (i = 1; i < n; i++)
    {
        s = (s + 1) * 2;
    }
    cout<<s;
    return 0;
}

3 个赞

不用那么麻烦

#include<bits/stdc++.h>
using namespace std;
int n;
int peach(int x){
	if(x==n) return 1;
	return (peach(x+1)+1)*2;
}
int main(){
	cin>>n;
	cout<<peach(1);
	return 0;
}
2 个赞
#include<bits/stdc++.h>
using namespace std;
int n,ans=1;
int main(){
	cin>>n;
	for(int i=1;i<=n-1;i++){
		ans=(ans+1)*2;
	}
	cout<<ans;
    return 0;
}
2 个赞