当前位置:网站首页>[c language] PTA 7-63 falling ball
[c language] PTA 7-63 falling ball
2022-07-29 04:29:00 【LastWhisperw】
The ball falls freely from a given height , Bounce back to half the original height after touching the ground , And then fall , Bounce back ,……, So again and again . Ask where the ball is n The next landing , How much distance has it traveled in the air ? The first n What is the height of the rebound ?
Input format :
Input gives two nonnegative integers in one line , Are the initial height of the ball and n, Are in the range of long integers .
Output format :
Output the balls in order in one line n The distance traveled in the air during the first landing 、 And the first n The height of the second rebound , Separated by a space , Keep one decimal place . The calculation results should not exceed the double precision range .
sample input :
33 5No blank lines at the end
sample output :
94.9 1.0No blank lines at the end
#include<stdio.h>
int main(){
int n,h0;
double h;
double s;
int i;
scanf("%d %d",&h0,&n);
h=(double)h0;
s=-(double)h0;// For convenience s=s+2*h So deal with it in advance s
if(n==0){// No more words Why 0 The secondary rebound height is also 0 Well ??
printf("%.1f %.1f",0.0,0.0);
}
else{
for(i=1;i<=n;i++){
s=s+2*h;
h=h/2;
// printf("%.1f %.1f\n",s,h);
}
printf("%.1f %.1f",s,h);
}
return 0;
}边栏推荐
- 不会就坚持66天吧 权重生成随机数
- Exception handling: pyemd or pyemd not found
- 不会就坚持64天吧 查找插入位置
- 恒星科通邀您“湘”约第24届中国高速公路信息化大会暨技术产品展示会
- Post export data, return
- Coding questions encountered in the interview
- Sign the college entrance examination
- redux快速上手
- Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan
- C语言:浅谈各种复杂的声明
猜你喜欢

Machine vision Series 2: vs DLL debugging

Use of construction methods

不会就坚持68天吧 狒狒吃香蕉

TypeError: Cannot read properties of undefined (reading ‘then‘)

Deploy Jenkins using containers

12. Priority queue and inert queue

14. Haproxy+kept load balancing and high availability

Record of problems encountered in ROS learning

你真的会写Restful API吗?

Unity基础(3)—— unity中的各种坐标系
随机推荐
Idea small settings
Update learning materials daily
Redux quick start
6. Pytest generates an allure Report
Sequence list and linked list
14. Haproxy+kept load balancing and high availability
Use of construction methods
不会就坚持71天吧 链表排序
论pyscript使用感想(实现office预览)
C language: talking about various complex statements
VScode 一键编译和调试
Back propagation process of manual BP neural network
es6和commonjs对导入导出的值修改是否影响原模块
The pit I walked through: the first ad Sketchpad
10. Fallback message
Don't insist on 66 days. Weight generates random numbers
Installation and use of stm32cubemx (5.3.0)
Introduction and examples of parameters in Jenkins parametric construction
Not for 60 days, magical dictionary
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)