阅读程序(1) 1-6题 组合题 #include #include 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 << 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,完成下面的判断题和单选题:
正确答案:判断题答案B。将t从int改为double,比较与sqrt计算精度会变,可能影响结果,故错误。
试卷来源:2021 CSP-S提高级(第一轮)C++真题