QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379331 | #8030. Traveling in the Grid World | comeintocalm# | WA | 1ms | 3844kb | C++17 | 982b | 2024-04-06 17:08:56 | 2024-04-06 17:08:56 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
const db eps = 1e-9;
int T;
int n, m;
db ans;
int gcd (int x, int y) {
return y ? gcd (y, x % y) : x;
}
int Gcd (int x, int y) {
if (!x || !y) return 1;
return gcd (x, y);
}
db calc (db x, db y) {
return sqrtl (x * x + y * y);
}
void work() {
//cout << 'a' << endl;
int x = 0, y = 0;
db fk = ((db) m) / n;
//cout << x << " " << y << endl;
while (x != n || y != m) {
if (x == n) ++y;
else if (y + 1 < (int)(fk * x + 1 - eps)) ++y;
else ++x;
if (Gcd (x, y) == 1 && Gcd (n - x, m - y) == 1)
ans = min (ans, calc (x, y) + calc (n - x, m - y));
//cout << x << " " << y << endl;
}
}
int main() {
int i,j,k;
scanf ("%d", &T);
while (T--) {
scanf ("%d%d", &n, &m);
ans = 1e18;
//cout << gcd (n, m);
if (Gcd (n, m) == 1) ans = calc (n, m);
else work(), swap (n, m), work();
printf ("%.12lf", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3844kb
input:
2 2 2 2 3
output:
3.2360679775003.605551275464
result:
wrong output format Expected double, but "3.2360679775003.605551275464" found