方法一:
用数学运算化简,本题化为不等式
(2的x次方)*0.104/1000 > 8848
则x > log(2为底)(8848*1000/0.104)的对数的最小整数
则C程序可以简化为:
#include <stdio.h>
#include <math.h>
int main() {
double x = log10(8848*1000/0.104)/log10(2)
printf("%.0f\n", ceil(x)) //输出次数
return 0
}
方法二:
纯程序法,每折一次,都计算当前的高度,与8848做对比,>8848时,完成。
#include <stdio.h>
int main() {
int i = 0
double h=0.0f
while (h<8848.0) { //这里使用了while循环,也可以改用for, do ... while等
h = pow(2, ++i)*0.104/1000 //化为米
}
printf("%d\n", i)
return 0
}
很简单,如果n = 1是折叠1次,应该为纸张的厚度*2,也就是0.05*1。为0.1mm。但是根据本答案提供的式子m*2^(n-1),答案应为m也就是0.05。在此即跟题意有所出入。
提供Python过程参考程序:
thick = 0.05x = 0
while thick <= 8848000:
thick 贺高塌*= 2
x += 1
print(thick, x)
显示效果如下:
次数 纸张厚度
0 0.05 禅圆
1 0.1
2 0.2
3 0.4
4 0.8
5 1.6
6 3.2
7 6.4
8 12.8
9 25.6
10 51.2
11 102.4
12 204.8
13 409.6
14 819.2
15 1638.4
16 3276.8 念腊
17 6553.6
18 13107.2
19 26214.4
20 52428.8
21 104857.6
22 209715.2
23 419430.4
24 838860.8
25 1677722
26 3355443
27 6710886
28 13421773
答案应为28次。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)