QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#709554 | #8030. Traveling in the Grid World | UESTC_DECAYALI# | TL | 479ms | 3964kb | C++20 | 1.1kb | 2024-11-04 15:26:26 | 2024-11-04 15:26:26 |
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)
{
for (RI q=1LL*m*p/n;q>=0;--q)
{
if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q)) continue;
ans=min(ans,dist(p,q)+dist(n-p,m-q)); break;
}
}
for (RI q=1;q<=m;++q)
{
for (RI p=1LL*n*q/m;p>=0;--p)
{
if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q)) continue;
ans=min(ans,dist(p,q)+dist(n-p,m-q)); break;
}
}
printf("%.15lf\n",ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3964kb
input:
2 2 2 2 3
output:
3.236067977499790 3.605551275463989
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 3752kb
input:
225 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 ...
output:
1.414213562373095 2.236067977499790 3.162277660168380 4.123105625617661 5.099019513592784 6.082762530298219 7.071067811865476 8.062257748298549 9.055385138137417 10.049875621120890 11.045361017187261 12.041594578792296 13.038404810405298 14.035668847618199 15.033296378372908 2.236067977499790 3.2360...
result:
ok 225 numbers
Test #3:
score: 0
Accepted
time: 92ms
memory: 3940kb
input:
6000 119 101 13 90 96 3 20 99 42 79 57 22 78 138 42 157 179 93 195 12 24 195 62 129 31 166 128 9 46 118 123 113 99 128 187 45 154 84 24 109 143 91 96 100 146 168 115 98 176 36 99 70 198 174 119 33 130 92 184 9 56 196 6 118 136 166 150 118 178 43 105 47 36 4 132 162 171 53 37 180 11 171 77 67 199 51 ...
output:
156.083311087380508 90.934042030473933 96.046886075716060 101.000000000000000 89.470665583754325 61.098281481560512 158.518156028175156 162.520767903674397 201.717624415914628 195.368884346966837 196.471374493754354 143.125818774950602 168.869772309907489 128.316016147634514 126.649125933847046 167....
result:
ok 6000 numbers
Test #4:
score: 0
Accepted
time: 479ms
memory: 3936kb
input:
1400 231 870 23 319 363 117 561 492 841 470 849 886 2 611 921 397 227 916 669 867 874 371 533 16 841 789 782 469 367 291 778 136 694 120 593 89 22 575 6 44 180 871 661 554 397 860 265 547 521 412 809 804 6 554 272 867 240 695 408 900 917 926 47 747 748 750 321 151 291 114 330 31 543 194 387 432 144 ...
output:
900.144988346139598 319.828078817354594 381.389564951911780 746.180273168174381 963.421506922074059 1227.109204594277344 611.003273313654176 1002.920734654538933 943.708111653174228 1095.102734920367084 949.482490623181548 533.240096016794269 1153.170412384917199 911.857993330101863 468.369512244338...
result:
ok 1400 numbers
Test #5:
score: -100
Time Limit Exceeded
input:
140 3868 307 1542 8425 7856 1284 8129 8657 773 3877 3073 1195 9579 2327 4058 1337 7080 2717 4183 8192 6189 9162 4094 9648 8098 864 5240 9869 6891 8861 9787 7768 321 97 3839 1384 3271 461 1031 8399 7425 278 6201 2581 2426 9301 3153 6278 3317 9760 34 6044 328 9027 9636 6166 8786 9001 9148 1501 6941 61...