当前位置:网站首页>OJ's daily practice -- falling and bouncing ball
OJ's daily practice -- falling and bouncing ball
2022-04-23 00:07:00 【KJ. JK】
Problem description :
A ball from M Free fall at a height of meters , Return to half the original height after each landing , And then fall . It is in the first place. N How high does it bounce on the first landing ? The first N How many meters did the first landing pass ? Keep two decimal places .
Input
M(M<10000M<10000)、N(M<100M<100) An integer separated by two spaces
Output
It is in the first place. N How high does it bounce on the first landing ? How many meters in total ? After rounding , Retain 2 Decimal place , Whitespace separated , Put it in a row
Examples
Input
4 2
Output
1.00 8.00
Java Code :
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner rd = new Scanner(System.in);
double high = rd.nextDouble();
double n = rd.nextDouble();
double sum = 0;
for (int i = 1; i <= n; i++) {
if (i == 1) {
sum = sum + high;
} else {
sum = sum + high * 2;
}
high = high / 2;
}
System.out.printf("%.2f" + " ", high);
System.out.printf("%.2f", sum);
}
}
C Code :
#include<stdio.h>
int main(){
int i,n;
double high,sum=0.0;
scanf("%lf %d",&high,&n);
for(i=1;i<=n;i++){
// use for() Loop to simulate the rebound process ,
// Don't forget the height of the rebound and the height of the final rebound
// Other intermediate processes are twice the rebound height .
if(i==1){
sum+=high; // On the first landing
}
else{
sum+=high*2; // The intermediate process is twice the rebound height .
}
high=high/2; // Bounce height
}
printf("%.2lf %.2lf",high,sum);
}
python Code :
m,n=map(int,input().split())
s=m
for i in range(n):
m=m/2
s+=m*2
print("%.2f %.2f"%(m,s-m*2))
author :KJ.JK
This article is only for communication learning , Without the permission of the author , Prohibited reproduced , Let alone for other purposes , Offenders will investigate .
If the article is helpful to you , Welcome to praise or star, Your support is the greatest encouragement to the author , The shortcomings can be corrected in the comments section , Communication and learning
版权声明
本文为[KJ. JK]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222213380631.html
边栏推荐
- SystemVerilog verification - Test Platform writing guide learning notes (3): connecting design and test platform
- 【ACM】90. Subset II (the de duplication problem of the same tree layer first needs to sort the array (use sort))
- Target detection model regression anchor offset and other problems
- 选中所有的文字
- PHP one-dimensional array de duplication
- Notes on "Introduction to dynamic programming" (under update)
- Shell脚本笔记(5)- 本的条件语句
- API接口知识小结
- Go language - use CO process to efficiently calculate the accumulation of each number in 0-2000
- Reg regular expression learning notes
猜你喜欢
随机推荐
Mysql的字段类型详解
3D旋转动画
SystemVerilog verification - Test Platform preparation guide learning notes (1): data types
常见的社群玩法盘点,你做的是哪一种?
L1-066 cat is liquid (5 points)
STM32F103 independent watchdog
Bonner ultrasonic sensor t30uxda
获取某一点的颜色
Ansible Yum warehouse
基于.NetCore开发博客项目 StarBlog - (3) 模型设计
【ACM】90. 子集 II(同一树层的去重问题首先要对数组进行排序(使用sort))
Font adaptation
Data type not supported by ice's mice profiler
Conditional judgment (while loop & for & switch loop & if else judgment)
Install the most complete version of ActiveMQ under the official website in 2022 and the official website access method
FCOS中相较传统anchor-based方法中独特的地方
Gets the color of a point
Day81 (dynamic programming, cross tree traversal)
L1-070 eating hot pot (15 points)
解决工业缺陷检测小样本问题





![[VMware] VMware esxi 6.7 installation](/img/c2/5d9c55bc0931ed7c87a9e3e5f7f15f.png)

