当前位置:网站首页>[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 5
No blank lines at the end
sample output :
94.9 1.0
No 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;
}
边栏推荐
- Star a pathfinding in LAYA
- C language: structure simple syntax summary
- Don't stick to it for 68 days. Baboons eat bananas
- 不会就坚持63天吧 最大的异或
- Installation and use of stm32cubemx (5.3.0)
- It won't last for 70 days. The k-largest number in the array
- Multi rotor six axis hardware selection
- 不会就坚持65天吧 只出现一次的数字
- Niuke IOI weekly 27 popularity group
- i++与++i详解
猜你喜欢
用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案
LeetCode_ Stack topics
Webrtc realizes simple audio and video call function
Installation and use of stm32cubemx (5.3.0)
Dasctf2022.07 empowerment competition
VScode 一键编译和调试
STL source code analysis (Hou Jie) notes - STL overview
The third ACM program design competition of Wuhan University of Engineering
Machine vision series 3:vs2019 opencv environment configuration
不会就坚持65天吧 只出现一次的数字
随机推荐
Update learning materials daily
Won't you insist on 71 days? List sorting
Won't you just stick to 62 days? Sum of words
6. Pytest generates an allure Report
MySQL - clustered index and secondary index
Record of problems encountered in ROS learning
不会就坚持66天吧 权重生成随机数
Pyqt5 learning pit encounter and pit drainage (3) background picture coverage button style and check button status
What is the difference between field, variable and property
kotlin的List,Map,Set等集合类不指定类型
No, just stick to it for 59 days
10.回退消息
On the use of pyscript (realizing office preview)
Deep learning training strategy -- warming up the learning rate
15.federation
Leftmost prefix principle of index
mpc5744p简介与OpenSDA固件更新
Pytorch fixed random seed & recurrence model
pyscript无法引入包
9. Delay queue