--- tags: 题解 --- # 题解:狙击oi爷 题目链接 https://vjudge.net/contest/434922#problem/F 对于二维的情况,起点有两条边可走,接着也有两条边可走,按电阻公式 $\dfrac{1}{\dfrac{1}{R}+\dfrac{1}{R}}+\dfrac{1}{\dfrac{1}{R}+\dfrac{1}{R}}=R$ 题目只要求出总电阻是R的多少倍,所以接下来我们直接令$R=1$ 原式可变换为 $\dfrac{1}{2}+\dfrac{1}{2}=1$ 对于三维的情况,起点有3条边可走,接着是6条边,最后3条边,按公式得 $\dfrac{1}{3}+\dfrac{1}{6}+\dfrac{1}{3}=\dfrac{5}{6}$ 对于四维的情况,起点有4条边可走,接着是12条边,再是12条边,最后4条边,按公式得 $\dfrac{1}{4}+\dfrac{1}{12}+\dfrac{1}{12}+\dfrac{1}{4}=\dfrac{2}{3}$ 注意以上式子左边分母的规律,分别是 $1 1\times 2$ $1 2 1\times 3$ $1 3 3 1 \times 4$ 这就是杨辉三角 于是可得代码 ```cpp #include <iostream> using namespace std; int main(void) { int n, t; cin >> t; for (int i = 0; i < t; i++) { cin >> n; double sum = 1.0 / n, cur = n; for (int j = n - 1; j > 0; j--) { cur = cur * j / (n - j); sum += 1.0 / cur; } cout << sum << endl; } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up