QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#379643#8030. Traveling in the Grid Worldcomeintocalm#WA 0ms3820kbC++171.1kb2024-04-06 18:01:452024-04-06 18:01:57

Judging History

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

  • [2024-04-06 18:01:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2024-04-06 18:01:45]
  • 提交

answer

#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;

const db eps = 1e-10;
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 ((LL)(y + 1) * n < (LL) m * x) ++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() {
	//freopen("rdin.in", "r", stdin);
	//freopen("x.out", "w", stdout);
	int i,j,k;
	//cout << (int) (1.99) << endl;
	scanf ("%d", &T);
	//T = 1;
	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 ("%.15f", ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3820kb

input:

2
2 2
2 3

output:

3.2360679774997903.605551275463989

result:

wrong output format Expected double, but "3.2360679774997903.605551275463989" found