QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#709607 | #8030. Traveling in the Grid World | UESTC_DECAYALI# | WA | 0ms | 3872kb | C++20 | 1.0kb | 2024-11-04 15:45:20 | 2024-11-04 15:45:20 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cassert>
#define int long long
#define RI register int
#define CI const int&
using namespace std;
int t,n,m;
signed main()
{
for (scanf("%lld",&t);t;--t)
{
scanf("%lld%lld",&n,&m);
int g=__gcd(n,m);
auto dist=[&](CI x,CI y)
{
return sqrt(1LL*x*x+1LL*y*y);
};
if (g==1) { printf("%.15lf\n",dist(n,m)); continue; }
double ans=1e18;
for (RI p=1;p<=n;++p)
{
int q=1LL*m*p/n;
if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q))
{
//do nothing
} else ans=min(ans,dist(p,q)+dist(n-p,m-q));
}
for (RI q=1;q<=m;++q)
{
int p=1LL*n*q/m;
if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q))
{
//do nothing
} else ans=min(ans,dist(p,q)+dist(n-p,m-q));
}
printf("%.15lf\n",ans);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3872kb
input:
2 2 2 2 3
output:
1000000000000000000.000000000000000 3.605551275463989
result:
wrong answer 1st numbers differ - expected: '3.2360680', found: '1000000000000000000.0000000', error = '309016994374947392.0000000'