当前位置:网站首页>OJ每日一练——猴子吃桃问题
OJ每日一练——猴子吃桃问题
2022-04-22 22:14:00 【KJ.JK】
问题描述:
猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个。 第二天早上又将剩下的桃子吃掉一半,又多吃一个。以后每天早上都吃了前一天剩下的一半零一个。 到第N天早上想再吃时,见只剩下一个桃子了。求第一天共摘多少桃子。
输入
N
输出
桃子总数
样例
输入
10
输出
1534
Java代码:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner rd=new Scanner(System.in);
int n =rd.nextInt(); //输入天数
int a=1; //剩最后一个桃子
for(int i=1;i<n;i++) {
a=(a+1)*2; //每天都吃掉一半加1个
}
System.out.println(a);
}
}
C代码:
#include <stdio.h>
int main(){
int a;
scanf("%d",&a);
int i=1;
int sum=1;
while(i<a){
sum=(sum+1)*2;
i++;
}
printf("%d",sum);
}
作者:KJ.JK
本文仅用于交流学习,未经作者允许,禁止转载,更勿做其他用途,违者必究。
文章对你有所帮助的话,欢迎给个赞或者 star,你的支持是对作者最大的鼓励,不足之处可以在评论区多多指正,交流学习
版权声明
本文为[KJ.JK]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_47384542/article/details/124354964
边栏推荐
- GBase 8s V8.8 SQL 指南:教程-6.2.1(2)
- Regular expression of JS
- What is the magic of moonbirds NFT, which became popular overnight?
- NLP direction -- interview and written test question set (7): pre training model Bert
- 【玩转Lighthouse】搭建即收即毁的临时邮箱系统
- 外部中断---------stm32f407zet6
- Fastadmin dynamic assignment drop-down box
- Advanced multithreading (6) -- locking mechanism
- JS solving power deduction daily question (8) -- 396 Rotation function (2022-4-22)
- 安装scVI及使用教程
猜你喜欢

ACL2022 | 利用中文语言层级异质图强化预训练语言模型

【4.1】flink窗口算子的trigger触发器和Evictor清理器

线性基(各种模板+例题)

What is the working nature of Italian ATOS solenoid valve?

opcua协议如何在appinventor上使用?

396. 旋转函数 / 剑指 Offer II 013. 二维子矩阵的和

41.0:GemBox. Spreadsheet|. Document|. Pdf|. Presentation

TOOLS.INI‘does not contain a valid tool path

初学单片机点亮第一个外设--LED灯

【洛穀】P1162 填塗顏色(bfs)
随机推荐
安装AuthorizationPolicy和EnvoyFilter
2.58-编写程序is-little-endian,当在小端法机器上编译和运行时返回1,在大端法机器上编译和运行时则返回0。这个程序应该可以运行在任何机器上,无论机器的字长是多少。
中缀转后缀表达式(逆波兰式) 转 前缀表达式(波兰式)
Come to a Vue boss and see if there is an iframe cache scheme?
公众号配置伪静态防止出现页面路径加载问题
Advanced multithreading (8) -- thread pool
讲座录播|图数据库中的子图匹配算法-邹磊
No more simple intention lock
知识图谱开篇笔记
PHP one-dimensional array de duplication
【洛穀】P1162 填塗顏色(bfs)
ACL2022 | 利用中文语言层级异质图强化预训练语言模型
NLP direction -- interview and written test question set (7): pre training model Bert
Flutter混合开发
根据这个有效方法,UI自动化测试就是那么的简单
对话杨炯纬,快体现在抓住“红利”上,实际上TO B公司应该跑得慢一点
jsp的form表单提交给servlet但js失效问题
加法逆元(a^a=0)异或操作,这个并没有性能上的优势,只是一个智力游戏
GBase 8s V8.8 SQL 指南:教程-6.2.2(3)
Catering industry cashier system source code, C # Net + MSSQL WPF