QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645427#8030. Traveling in the Grid WorldATM12345WA 0ms3884kbC++171.2kb2024-10-16 18:18:392024-10-16 18:18:46

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 18:18:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3884kb
  • [2024-10-16 18:18:39]
  • 提交

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'