import java.util.Scanner; //题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半:再落下,求它在第10次落地时,共经过多少米?第10次反弹多高? public class BallTest { public static void main(String[] args) { double firsthight; int n; Scanner in = new Scanner (System.in);//从键盘读取两个数据 System.out.println…
a = [100] #每个‘反弹落地’过程经过的路程,第1次只有落地(100米) h = 100 #每个‘反弹落地’过程,反弹的高度,第1次为100米 print('第1次从%s米高落地,走过%s米,之后又反弹至%s米.' % (h, a[0], h/2)) for i in range(2,11): #第1次已初始化,再循环9次 a.append(h) #先计算路程,再高度减半,因为一个‘反弹落地’为2个高度 h = h / 2 print('第%s次从%s米高…
def get_height(n): if n==1: eturn 150 return 100+sum([200*pow(0.5,i) for i in range(1,n)])+100*pow(0.5,n) for i in range(1,5): print get_height(i) 150 225.0 262.5 281.25结果如上, 递归法求解如下:def get_height(n): if n==1: eturn 150 return get_height(n-1)+100*po…
include #include<vector> using namespace std; class Balls { public: int calcDistance(int A, int B, int C, int D) { // write code here return calcDis(A) + calcDis(B) + calcDis(C) + calcDis(D); } int calcDis(int x) { float sum = x; float xx = x; while…