2020ICPC·小米 网络选拔赛热身赛 I-Integration

传送门:https://ac.nowcoder.com/acm/contest/8409/I

题意

$$求解\int_{0}^{+\infty }\frac{1}{\prod_{i=1}^n(a_i^2+x^2)}dx$$

思路

想要用分部积分求该定积分是非常非常困难的,而题目给出了$\int_{0}^{+\infty}\frac{1}{1+x^2}dx=\frac{\pi}{2}$,所以我们就想办法把这个连乘变成连加,这样就好求了。

当n=1时:

$$\int_{0}^{+\infty}\frac{1}{a^2+x^2}dx=\frac{1}{a^2}arctan(\frac{x}{a})_0^{+\infty}=\frac{\pi}{2a}$$

当n=2时:

只看让式子分解的部分:

$$\frac{1}{a^2+x^2}\frac{1}{b^2+x^2}=\frac{\alpha}{a^2+x^2}+\frac{\beta }{b^2+x^2}=\frac{\alpha b^2+\beta a^2 + x^2(\alpha + \beta)}{(a^2+x^2)(b^2+x^2)}$$

转化为:

$$\int_{0}^{+\infty }(\frac{1}{b^2-a^2})(\frac{1}{a^2+x^2})+(\frac{1}{a^2-b^2})(\frac{1}{b^2+x^2})dx=\frac{1}{b^2-a^2}*\frac{1}{2a}+\frac{1}{a^2-b^2}*\frac{1}{2b}$$

当n=3时:

$$\frac{1}{a^2+x^2}\frac{1}{b^2+x^2}\frac{1}{c^2+x^2}=\frac{\alpha}{a^2+x^2}+\frac{\beta}{b^2+x^2}+\frac{\gamma}{c^2+x^2}$$ $$=\frac{\alpha b^2c^2+\beta a^2c^2+\gamma a^2b^2+x^2(\alpha (b^2+c^2)+\beta (a^2+c^2)+\gamma (a^2+b^2))+x^4(\alpha+\beta+\gamma)}{(a^2+x^2)(b^2+x^2)(c^2+x^2)}$$

$$\int_{0}^{+\infty }\frac{1}{(a^2+x^2)(b^2+x^2)(c^2+x^2)}dx$$ $$=\frac{1}{(b^2-a^2)(c^2-a^2)} \frac{1}{2a}+\frac{1}{(a^2-b^2)(c^2-b^2)}\frac{1}{2b}+ \frac{1}{(a^2-c^2)(b^2-c^2)}\frac{1}{2c}$$

根据上面的列举,大大推断出该式子的规律,即对于

$$\int_{0}^{+\infty }\frac{1}{\prod_{i=1}^n(a_i^2+x^2)}dx$$

$$ans=\sum_{i=1}^n\frac{1}{2a_i}\left (\prod_{j=1\;j\neq i}^n\frac{1}{a_j^2-a_i^2} \right )$$

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
##include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pdd;

##define INF 0x3f3f3f3f
##define lowbit(x) x & (-x)
##define mem(a, b) memset(a , b , sizeof(a))
##define FOR(i, x, n) for(int i = x;i <= n; i++)

// const ll mod = 998244353;
const ll mod = 1e9 + 7;
// const double eps = 1e-6;
// const double PI = acos(-1);
// const double R = 0.57721566490153286060651209;

const int N = 105;

double dis(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

ll quick_pow(ll a, ll b) {
ll ans = 1;
while(b) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans % mod;
}

void solve() {
int n;
while(cin >> n) {
ll ans = 0;
ll a[30005];
for(int i = 1;i <= n; i++) {
cin >> a[i];
};
for(int i = 1;i <= n; i++) {
ll t = 1;
for(int j = 1;j <= n; j++) {
if(i == j) continue;
t = t * (((a[j] * a[j] % mod - a[i] * a[i] % mod) % mod + mod) % mod) % mod;
}
t = t * 2 % mod * a[i] % mod;
ans = (ans + quick_pow(t, mod - 2)) % mod;
}
cout << ans % mod << endl;
}
}

signed main() {
ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
//cout.tie(nullptr);
##ifdef FZT_ACM_LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
signed test_index_for_debug = 1;
char acm_local_for_debug = 0;
do {
if (acm_local_for_debug == '$') exit(0);
if (test_index_for_debug > 20)
throw runtime_error("Check the stdin!!!");
auto start_clock_for_debug = clock();
solve();
auto end_clock_for_debug = clock();
cout << "Test " << test_index_for_debug << " successful" << endl;
cerr << "Test " << test_index_for_debug++ << " Run Time: "
<< double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
cout << "--------------------------------------------------" << endl;
} while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
##else
solve();
##endif
return 0;
}

本文作者:jujimeizuo
本文地址https://blog.jujimeizuo.cn/2020/10/24/2020-icpc-xiaomi-i/
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0 协议。转载请注明出处!