在一行上输入一个整数
代表小球的初始高度。
第一行输出一个实数,代表小球在第五次落地时所经历的路程。
第二行输出一个实数,代表第五次反弹的高度。
由于实数的计算存在误差,当误差的量级不超过
时,您的答案都将被接受。具体来说,设您的答案为
,标准答案为
,当且仅当
时,您的答案将被接受。
1
2.875 0.03125
第一次反弹高度为
米,第二次反弹高度为
米,第三次反弹高度为
米,第四次反弹高度为
米,第五次反弹高度为
米。
截止第五次落地,总路程为
米。
import java.util.Scanner; /** * @author aiker * @since 2021/11/6 */ public class Main { private static double[] calculateTrail(double height, int times) { double[] result = new double[2]; double trail; if (times == 1) { result[0] = height; result[1] = height / 2; return result; } trail = height; for (int i = 1; i < times; i++) { trail += height; height /= 2; } result[0] = trail; result[1] = height / 2; return result; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { double nextInt = scanner.nextDouble(); double[] result = calculateTrail(nextInt, 5); System.out.println(result[0]); System.out.println(result[1]); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int high = in.nextInt(); float fhigh = high; float sumhigh=0; for(int i=0;i<4;++i){ sumhigh+=fhigh/2+fhigh; fhigh/=2; } sumhigh+=fhigh; fhigh/=2; System.out.println(sumhigh+"\n"+fhigh); } }
#include<iostream> #include<stdio.h> using namespace std; int main() { double h; cin>>h; double ans=h; //第一次落地时的高度 for(int i=0;i<4;++i) { ans+=h; //反弹的高度是原来的一半,但是起-落的过程经历的距离是反弹高度的两倍,仍是h h/=2; //第i+2次落地之前弹起的高度 } h/=2; printf("%0.6f\n%0.6f\n",ans,h); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int data; while(cin>>data) { float h,sum,flag1,flag2,flag3,flag4,flag5; h=data; flag1=h/2; flag2=flag1/2; flag3=flag2/2; flag4=flag3/2; flag5=flag4/2; sum=flag1+flag2+flag3+flag4; sum*=2; sum+=data; cout<<sum<<endl; cout<<flag5<<endl; } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n =sc.nextInt(); g(n); } } public static void g(int n){ if(n<0){ System.out.println(0); } double h5 = (double)n/32; double len = 0; for(int i=1;i<5;i++){ len+=(n/Math.pow(2, i))*2; } len+=n; System.out.println(len); System.out.println(h5); } }
#include <iostream> //输出第5次落地时经历来多少米,是不包括第五次可落地后回弹的高度的, //总共经历的米数 == 最初的height + 中间每一次回弹高度*2 using namespace std; int main() { int height; while(cin >> height) { double res = height; int tmp = 2; for(int i = 1;i<=4;i++) { res += ((double)height/tmp)*2; tmp = tmp*2; } cout<<res<<endl<<(double)height/32<<endl; } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextDouble()) { int height = scanner.nextInt(); double total = height; double curheight = height; for (int i = 1; i < 5; i++) { total = total + curheight; curheight = curheight / 2; } curheight = curheight / 2; try { System.out.println(sisheliuru(total)); System.out.println(sisheliuru(curheight)); } catch (Exception e) { System.out.println("error"); } } scanner.close(); } /** * 保留6位有效数字,对后面的数字实行四舍六入五留双,如果double结果有.0,去掉小数点 * * @param total * @return */ public static String sisheliuru(double total) { StringBuilder sBuilder = new StringBuilder(); int htotal = (int) total; String shtotal = htotal + ""; String stotal = total + ""; if (total == (int) total) { stotal = shtotal; } int haspoint = stotal.indexOf("."); if (stotal.length() <= 6 || (stotal.length() == 7 && haspoint != -1)) { return stotal; } if (shtotal.length() > 6) { sBuilder.append(shtotal.subSequence(0, 5)); int point6 = shtotal.charAt(5) - '0'; int point7 = shtotal.charAt(6) - '0'; if (point7 > 5) { sBuilder.append(point6 + 1); } else if (point7 < 5) { sBuilder.append(point6); } else { if (point6 % 2 == 0) { sBuilder.append(point6); } else { sBuilder.append(point6 + 1); } } for (int i = 0; i < shtotal.length() - 6; i++) { sBuilder.append("0"); } } else if (shtotal.length() == 6) { sBuilder.append(shtotal.subSequence(0, 5)); int point6 = shtotal.charAt(5) - '0'; if (haspoint != -1) { int point7 = stotal.charAt(haspoint + 1) - '0'; if (point7 > 5) { sBuilder.append(point6 + 1); } else if (point7 < 5) { sBuilder.append(point6); } else { if (point6 % 2 == 0) { sBuilder.append(point6); } else { sBuilder.append(point6 + 1); } } } else { sBuilder.append(point6); } } else { if (haspoint != -1) { sBuilder.append(stotal.subSequence(0, 6)); int point6 = stotal.charAt(6) - '0'; int point7 = stotal.charAt(7) - '0'; if (point7 > 5) { sBuilder.append(point6 + 1); } else if (point7 < 5) { sBuilder.append(point6); } else { if (point6 % 2 == 0) { sBuilder.append(point6); } else { sBuilder.append(point6 + 1); } } } else { sBuilder.append(stotal); } } return sBuilder.toString(); } }
#include<iostream> using namespace std; double journey(double &begin){ double total=begin; for(int i=1;i<5;i++){ total+=begin; begin/=2; } begin/=2; return total; } int main(){ int begin; while(cin>>begin){ double height=(double)begin; double total=journey(height); cout<<total<<endl<<height<<endl; } }
//画图做题 #include<iostream> using namespace std; int main(){ int a; while (cin >> a){ cout << (a*1.0) + (a*1.0 * 2 / (1 << 1)) + (a*1.0 * 2 / (1 << 2)) + (a*1.0 * 2 / (1 << 3)) + (a*1.0 * 2 / (1 << 4)) << endl; cout << (a*1.0 / (1 << 5)) << endl; } system("pause"); return 0; }
#include <iostream> using namespace std; int main() { double h; while (cin >> h) cout << 23 * h / 8 << endl << h/32 << endl; }敢敢单单
#include <iostream>
using namespace std;
double bounce(int height)
{
double high=(double)height;
for(int i=0;i<5;i++)
high/=2;
return high;
}
double Sum(int height)
{
double high=(double)height;
double sum=high;
for(int i=0;i<4;i++)
{
sum+=high;
high/=2;
}
return sum;
}
int main()
{
int high;
while(cin>>high)
{
cout<<Sum(high)<<endl;
cout<<bounce(high)<<endl;
}
return 0;
}
#include<iostream> using namespace std; double getJourney(double high) { double sum = high; for (int i = 0; i < 4; i++) { high = 1.0 * high / 2; sum += high * 2; } return sum; } double getTenthHigh(double high) { for (int i = 0; i < 5; i++) { high = high / 2.0; } return (double)high; } int main() { int height; while (cin >> height) { cout << getJourney(height) << endl; cout << getTenthHigh(height) << endl; } return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int main() { double h = 0.0; while(cin>>h) { double sumH = h; int n=4; while(n--) { sumH += h; h = h/2.0; } cout<<sumH<<endl; cout<<h/2.0<<endl; } return 0; }