题解:P16793 [蓝桥杯 2026 国 B] 玩具青蛙 邪修
并没有按照推算数学公式去计算答案,使用了另一种取巧的方式进行计算。
题意是需要计算最后的一个分式。那我们可以先通过程序计算出最后大概的浮点数:0.499877。
在通过暴力打表限制精度来看有哪些数符合大概范围的要求,最后打表内容如下:
- 2026 4053
- 4052 8106
- 6078 12159
- 8104 16212
并且由于篮球杯极度喜欢出跟本年份相关的题目,大胆推理出选带有本年份的答案,暨:2026+4053 = 6079
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
vector<double> a;
for(double i = 1;i <= 2026;i++){
double idx = (2 * i - 1) * (2 * i + 1);
a.push_back(idx);
}
double res = 0.0;
for(int i = 0;i<a.size();i++){
res += 1.0 / a[i];
}
cout << res << endl;
for(double i = 1;i<=10000;i += 1.0){
for(double j = 2;j<=20000;j += 1.0){
if(i / j >= res - 0.000000000000005 && i / j <= res + 0.000000000000005)
cout << i << " " << j << endl;
}
}
}
int main( )
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1;
// cin >> tt;
while(tt--){
solve();
}
}