1 条题解
-
0
自动搬运
来自洛谷,原作者为

TemplateClass
**搬运于
2025-08-24 23:12:20,当前版本为作者最后更新于2025-04-05 14:22:04,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
考虑把这个积分拆开,也就是:
$$\int _ 0 ^ 1 \frac{P(x)}{x ^ 2 + 1} \d x = \sum _ {k = 0} ^ {n} a _ k \int _ 0 ^ 1 \frac{x ^ k}{x ^ 2 + 1} \d x $$于是我们只需要考虑右边的那个积分就可以了。
令:
首先,我们可以发现:
$$I _ 0 = \int _ 0 ^ 1 \frac{1}{x ^ 2 + 1} \d x = [\arctan x] _ 0 ^ 1 = \frac{\pi}{4} $$$$I _ 1 = \int _ 0 ^ 1 \frac{x}{x ^ 2 + 1} \d x = \left[ \frac{1}{2} \ln (x ^ 2 + 1) \right] _ 0 ^ 1 = \frac{\ln 2}{2} $$接着,对于 ,我们有:
$$\begin{aligned} I _ k &= \int _ 0 ^ 1 \frac{x ^ k}{x ^ 2 + 1} \d x \\ &= \int _ 0 ^ 1 \frac{x ^ {k - 2} [(x ^ 2 + 1) - 1]}{x ^ 2 + 1} \d x \\ &= \int _ 0 ^ 1 x ^ {k - 2} \d x - \int _ 0 ^ 1 \frac{x ^ {k - 2}}{x ^ 2 + 1} \d x \\ &= \left[ \frac{x ^ {k - 1}}{k - 1} \right] _ 0 ^ 1 - I _ {k - 2} \\ &= \frac{1}{k - 1} - I _ {k - 2} \end{aligned} $$于是照这个算就行了,时间复杂度 。
#include<iostream> #include<cmath> #include<numbers> #include<iomanip> typedef long double ld; int n; ld ans = 0, I[3] = {std::numbers::pi / 4, std::log(2) / 2}; int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0), std::cout.tie(0); int n; std::cin >> n; for(int k = 0; k <= n; ++k) { int a; std::cin >> a; if(k > 1) I[k % 3] = 1. / (k - 1) - I[((k - 2) + 3) % 3]; ans += (ld)a * I[k % 3]; } std::cout << std::fixed << std::setprecision(10) << ans; return 0; }
- 1
信息
- ID
- 11793
- 时间
- 100ms
- 内存
- 512MiB
- 难度
- 4
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者