正在载入在线练习界面,本页内容可直接阅读…
AK CSP › CSP-S 2021 第一轮真题 › 第20题
CSP-S 2021 第一轮 第20题:当输入为“11111112”时,输出为()。
题目
#include <iostream>
#include <cmath>
using namespace std;
const double r = acos(0.5);
int a1, b1, c1, d1;
int a2, b2, c2, d2;
inline int sq(const int x) { return x * x; }
inline int cu(const int x) { return x * x * x; }
int main()
{
cout.flags(ios::fixed);
cout.precision(4);
cin >> a1 >> b1 >> c1 >> d1;
cin >> a2 >> b2 >> c2 >> d2;
int t = sq(a1 - a2) + sq(b1 - b2) + sq(c1 - c2);
if (t <= sq(d2 - d1)) cout << cu(min(d1, d2)) * r * 4;
else if (t >= sq(d2 + d1)) cout << 0;
else {
double x = d1 - (sq(d1) - sq(d2) + t) / sqrt(t) / 2;
double y = d2 - (sq(d2) - sq(d1) + t) / sqrt(t) / 2;
cout << (x * x * (3 * d1 - x) + y * y * (3 * d2 - y)) * r;
}
cout << endl;
return 0;
}
假设输入的所有数的绝对值都不超过 $1000$ ,完成下面的判断题和单选题:本小题
当输入为 1 1 1 1 1 1 1 2 时,输出为( )。
选项
- A. 3.1416
- B. 6.2832
- C. 4.7124
- D. 4.1888
答案
D
题解
答案是 D. 4.1888。
按照题目中带空格的输入,读入的变量为:
``cpp a1 = b1 = c1 = d1 = 1; a2 = b2 = c2 = 1; d2 = 2; ``
先计算:
``cpp t = (1 - 1)² + (1 - 1)² + (1 - 1)² = 0; ``
第一个判断条件为:
``cpp t <= (d2 - d1)² 0 <= 1 ``
条件成立,所以执行:
``cpp cout << cu(min(d1, d2)) * r * 4; ``
其中,cu(x) 表示 \(x^3\),acos(0.5) 表示余弦值为 \(0.5\) 的角度(弧度制),因此:
\[ r=\frac{\pi}{3},\qquad 1^3\times\frac{\pi}{3}\times4 =\frac{4\pi}{3}\approx4.1887902 \]
程序设置了固定保留 4 位小数,最终输出:
``text 4.1888 ``
真题版权归 CCF 所有,本站仅用于非商业教学用途。页面加载后可直接在线作答,作答记录保存在本浏览器或账号中。 京ICP备2026056990号-1
京公网安备11010502062986号