#2585. 2021 CSP-S1 真题 · 阅读程序1

2021 CSP-S1 真题 · 阅读程序1

2021 CSP-S1 真题(120 分钟,总分 100 分)

阅读程序1(共 6 题,共 12.0 分)

1.

#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,完成下面的判断题和单选题:

将第21行中t的类型声明从int改为double,不会影响程序运行的结果。( )

{{ select(1) }}

  • 正确
  • 错误

2. 将第 26、27 行中的“/ sqrt(t) / 2”替换为“/ 2 / sqrt(t)”,不会影响程序运行的结果。( )

{{ select(2) }}

  • 正确
  • 错误

3. 将第28行中的“x * x”改成“sq(x)”、“y * y”改成“sq(y)” ,不会影响程序运行的结果。( )

{{ select(3) }}

  • 正确
  • 错误

4. (2分)当输入为“0 0 0 1 1 0 0 1”时,输出为“1.3090”。( )

{{ select(4) }}

  • 正确
  • 错误

5. 当输入为“1 1 1 1 1 1 1 2”时,输出为( )。

{{ select(5) }}

  • “3.1416”
  • “6.2832”
  • “4.7124”
  • “4.1888”

6. 这段代码的含义为( )。

{{ select(6) }}

  • 求圆的面积并
  • 求球的体积并
  • 求球的体积交
  • 求椭球的体积并