QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#645427 | #8030. Traveling in the Grid World | ATM12345 | WA | 0ms | 3884kb | C++17 | 1.2kb | 2024-10-16 18:18:39 | 2024-10-16 18:18:46 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl '\n'
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int MAX = 1005;
int n, m;
bool check(int x, int y) {
return __gcd(x, y) == 1 && __gcd(n - x, n - y) == 1;
}
double dis(int x, int y) {
return sqrtl(x * x + y * y) + sqrtl((n - x) * (n - x) + (m - y) * (m - y));
}
void sol() {
cin >> n>> m;
double best = INFINITY;
if (__gcd(n, m)) {
best = sqrtl(n * n + m * m);
} else {
for (int x = 0; x <= n; x++) {
if (x != 0) {
int yf = (m * x - 1) / n;
if (check(x, yf)) {
best = min(best, dis(x, yf));
}
}
if (x != n) {
int yc = (m * x + n) / n;
if (check(x, yc)) {
best = min(best, dis(x, yc));
}
}
}
for (int y = 0; y <= m; y++) {
if (y != 0) {
int xf = (n * y - 1) / m;
if (check(xf, y)) {
best = min(best, dis(xf, y));
}
}
if (y != m) {
int xc = (n * y + m) / m;
if (check(xc, y)) {
best = min(best, dis(xc, y));
}
}
}
}
printf("%.20Lf\n", best);
}
#undef int
int main() {
IOS
int tt=1;
cin>>tt;
while (tt--)
sol();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3884kb
input:
2 2 2 2 3
output:
2.82842712474619009753 3.60555127546398929313
result:
wrong answer 1st numbers differ - expected: '3.2360680', found: '2.8284271', error = '0.1259680'