在一行上输入一个整数
代表小球的初始高度。
第一行输出一个实数,代表小球在第五次落地时所经历的路程。
第二行输出一个实数,代表第五次反弹的高度。
由于实数的计算存在误差,当误差的量级不超过
时,您的答案都将被接受。具体来说,设您的答案为
,标准答案为
,当且仅当
时,您的答案将被接受。
1
2.875 0.03125
第一次反弹高度为
米,第二次反弹高度为
米,第三次反弹高度为
米,第四次反弹高度为
米,第五次反弹高度为
米。
截止第五次落地,总路程为
米。
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
float h = in.nextFloat();
float lastHeight = height(5, h);
float total = sum(5, h);
System.out.println(total);
System.out.println(lastHeight);
}
public static float height(int times, float h) {
if (times == 1) {
return h / 2;
} else {
//后续每次弹起是前一次的一半
return height(times - 1, h) / 2;
}
}
public static float sum(int times, float h) {
if (times == 1) {
return h;
} else {
//当前经历总路程等于上一次的总路程,加上上一次反弹高度的两倍
return sum(times - 1, h) + height(times - 1, h) * 2;
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int height = scanner.nextInt();
float total = height;
double[] arr = new double[5];
arr[0] = height;
for (int i = 1; i < 5; i++) {
arr[i] = arr[i - 1] / 2;
total += arr[i] * 2;
}
System.out.println(total);
System.out.println(arr[4] / 2);
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double h = in.nextDouble();
double temp = h/2;
for(int i=1;i<5;i++){
h += temp*2;
temp= temp/2;
}
System.out.println(h);
System.out.println(temp);
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int high = in.nextInt();
//16 16 8;8 4;4 2;2 1;1
double fall = 0;
double temp = (double) high;
double sum = 0;
for (int i = 1; i <= 5; i++) {
fall = temp;
temp /=2;
if(i < 5){
sum += fall+temp;
}else{
sum +=fall;
}
}
System.out.println(sum);
System.out.println(temp);
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
float h = in.nextFloat();
float s = 0;
for(int i = 0; i < 5; i++){
s += (i == 0 ? h : 2*h);
h /= 2;
}
System.out.println(s);
System.out.println(h);
}
} public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int n = in.nextInt();
double distance5th = n*2.87500;
double heights5th = n*0.031250;
System.out.println(distance5th);
System.out.println(heights5th);
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
// 总路程
System.out.println(a * 2.875f);
// 最后一次反弹高度
System.out.println(a * 0.03125f);
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
Double height=in.nextDouble();
Double sum=0.0;
for(int i=1;i<=5;i++){
sum+=height+height/2;
height/=2;
}
sum-=height;
System.out.println(sum);
System.out.print(height);
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 获取小球的初始高度
double height = in.nextDouble();
// 定义一个变量,表示小球经过的路程
double distance = 0;
// 定义一个变量,表示小球反弹的高度
double reboundHeight = 0;
// 循环模拟反弹
for (int i = 0; i < 5; i++) {
if (i == 0) {
// 首次反弹为小球初始高度一半
reboundHeight = height / 2;
// 首次距离为小球初始高度
distance = height;
} else {
// 小球经过的距离等于初始高度+2倍反弹高度
distance = distance + reboundHeight*2;
// 每循环一次,反弹高度为原来的一半
reboundHeight = reboundHeight / 2;
}
}
// 输出结果
System.out.println(distance);
System.out.println(reboundHeight);
}
} import java.io.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s;
while ((s = br.readLine()) != null) {
double H = Double.parseDouble(s);
double S = 0; //记录总路程
double h;
for (int i = 1; i < 5; i++) {
h = H / 2;
S += H + h;
H = h;
}
S += H;
h = H / 2;
System.out.println(S + "\n" + h);
}
}
}