更佳的阅读体验:洛谷 P10314 题解
简要题意:给定浮点数 $x$,求 $f(x) = x - 0.5 + \dfrac{\arctan (\cot (\pi x))}{\pi}$ 的值。
数学库中提供了我们想要的函数,直接输出即可。有以下几个细节需要注意:
- $\arctan$ 对应的函数是
atan()
。 - $\cot$ 没有直接的函数对应,但 $\cot \alpha = \dfrac{1}{\tan \alpha}$。
- $\pi$ 可以使用常量
M_PI
,无需手动计算。
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int t;
double x;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
for (cin >> t; t; --t) {
cin >> x;
cout << fixed << setprecision(6) << x - 0.5 + atan(1 / tan(M_PI * x)) / M_PI << '\n';
} return 0;
}