aaron0919 @ 2025-01-10 19:50:34
错误原因(看不懂)
Wrong Answer.wrong answer 1st numbers differ - expected: '98580.2390390691', found: '33587.6307142972', error = '0.6592863738'
记录
code
#include <bits/stdc++.h>
using namespace std;
const double ESP = 1e-9;
int main()
{
cin.tie(0)->sync_with_stdio(0);
cout.precision(15);
int T, n, m;
cin >> T;
while (T--)
{
cin >> n >> m;
if (__gcd(n, m) == 1)
{
cout << sqrt(n * n + m * m) << '\n';
}
else
{
double ans = 1e9, k = 1.0 * m / n;
for (int x = 1; x < n; x++)
{
int y = k * x - 1;
if (__gcd(n - x, m - y) == 1 && __gcd(x, y) == 1 && fabs(y - k * x) > ESP)
{
ans = min(ans, sqrt(x * x + y * y) + sqrt((n - x) * (n - x) + (m - y) * (m - y)));
}
y++;
if (__gcd(n - x, m - y) == 1 && __gcd(x, y) == 1 && fabs(y - k * x) > ESP)
{
ans = min(ans, sqrt(x * x + y * y) + sqrt((n - x) * (n - x) + (m - y) * (m - y)));
}
y++;
if (__gcd(n - x, m - y) == 1 && __gcd(x, y) == 1 && fabs(y - k * x) > ESP)
{
ans = min(ans, sqrt(x * x + y * y) + sqrt((n - x) * (n - x) + (m - y) * (m - y)));
}
}
cout << ans << '\n';
}
}
}