この質問のせいで、大学の入試で物理学を学んでいないことがほとんど疑われました
意図
彼はその任意の2つのエンドポイントの抵抗を測定し、抵抗値はすべて2 a 2aです。2 a
三角形の抵抗が2a 2aであることを示します2の代わりに側に抵抗のある2 2A2 a
実際には各側の抵抗Rは
1 R + 1 2 R = 2 a \ frac {1} {R} + \ frac {1} {2R} = 2a R1+2 R1=2 a
R = 3 a R = 3aであることがわかりますR=3 a
だからあなたは漸化式を得ることができます
an + 1 = 1 1 1 1 an + 4 3 + 3 + 1 3 a_ {n + 1} = \ frac {1} {\ frac {1} {\ frac {1} {\ frac {1} {a_ { n}} + \ frac {4} {3}} + 3} + \ frac {1} {3}} aN + 1=an個1+341+ 31+311
Pythonでテーブルをプレイする
res = 5 / 3
print('%.20f' % res)
for i in range(20):
res = 1 / ((1 / (1 / (1 / res + 4 / 3) + 3)) + 1 / 3)
print('%.20f' % res)
取得する
1.66666666666666674068
1.61904761904761906877
1.61805555555555535818
1.61803444782168193150
1.61803399852180329610
1.61803398895790206957
1.61803398875432269399
1.61803398874998927148
1.61803398874989712297
1.61803398874989490253
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
1.61803398874989468048
これはa = 1 a = 1a=1の場合、最後にaを掛けること
は明らかです。文字列ストリームを使用して、テーブルに直接アクセスするだけです。
#include <bits/stdc++.h>
using namespace std;
vector<double> res;
void init() {
res.push_back(1.66666666666666674068);
res.push_back(1.61904761904761906877);
res.push_back(1.61805555555555535818);
res.push_back(1.61803444782168193150);
res.push_back(1.61803399852180329610);
res.push_back(1.61803398895790206957);
res.push_back(1.61803398875432269399);
res.push_back(1.61803398874998927148);
res.push_back(1.61803398874989712297);
res.push_back(1.61803398874989468048);
res.push_back(1.61803398874989468048);
res.push_back(1.61803398874989468048);
res.push_back(1.61803398874989468048);
res.push_back(1.61803398874989468048);
res.push_back(1.61803398874989468048);
}
void solve() {
int t;
cin >> t;
init();
while (t--) {
string str;
double a;
cin >> str >> a;
if (str.length() > 2) {
cout << fixed << setprecision(10) << res.back() * a << endl;
continue;
}
stringstream ss(str);
int n;
ss >> n;
if (n > res.size() - 1) {
cout << fixed << setprecision(10) << res.back() * a << endl;
} else {
cout << fixed << setprecision(10) << res[n - 1] * a << endl;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long long test_index_for_debug = 1;
char acm_local_for_debug;
while (cin >> acm_local_for_debug) {
cin.putback(acm_local_for_debug);
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;
}
#else
solve();
#endif
return 0;
}