QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#873255 | #8030. Traveling in the Grid World | luqyou | AC ✓ | 351ms | 4096kb | C++14 | 1.3kb | 2025-01-26 11:02:05 | 2025-01-26 11:02:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
#define pii pair<int,int>
#define pb push_back
#define umap unordered_map
#define mset multiset
#define pq priority_queue
#define ull unsigned long long
#define i128 __int128
int x,y;
double calc(int xx,int yy){
if(!(__gcd(xx,yy)==1&&__gcd(x-xx,y-yy)==1)) return 1e9;
if((double)(yy*1.0/xx)==(double)((y-yy)*1.0/(x-xx))) return 1e9;
return hypot(xx,yy)+hypot(x-xx,y-yy);
}
void solve(){
cin>>x>>y;
if(__gcd(x,y)==1) return cout<<fixed<<setprecision(9)<<hypot(x,y)<<endl,void();
double res=x+y;
for(int i=1;i<x;i++){
if(__gcd(x-i,y)==1) res=min(res,hypot(x-i,y)+i);
}
for(int i=1;i<y;i++){
if(__gcd(y-i,x)==1) res=min(res,hypot(y-i,x)+i);
}
double k=(double)(y*1.0/x);
for(int i=1;i<x;i++){
double j=k*i;
int yy=j;
if(yy<y) res=min(res,calc(i,yy));
if(yy+1<y) res=min(res,calc(i,yy+1));
if(yy-1<y) res=min(res,calc(i,yy-1));
}
cout<<fixed<<setprecision(9)<<res<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
/*
Samples
input:
output:
THINGS TODO:
检查freopen,尤其是后缀名
检查空间
检查调试语句是否全部注释
*/
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4096kb
input:
2 2 2 2 3
output:
3.236067977 3.605551275
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 4096kb
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.414213562 2.236067977 3.162277660 4.123105626 5.099019514 6.082762530 7.071067812 8.062257748 9.055385138 10.049875621 11.045361017 12.041594579 13.038404810 14.035668848 15.033296378 2.236067977 3.236067977 3.605551275 4.576491223 5.385164807 6.359173603 7.280109889 8.261297174 9.219544457 10.205...
result:
ok 225 numbers
Test #3:
score: 0
Accepted
time: 46ms
memory: 4096kb
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.083311087 90.934042030 96.046886076 101.000000000 89.470665584 61.098281482 158.518156028 162.520767904 201.717624416 195.368884347 196.471374494 143.125818775 168.869772310 128.316016148 126.649125934 167.026943934 161.817798774 192.338243727 175.419569873 111.610931364 169.499332026 138.621799...
result:
ok 6000 numbers
Test #4:
score: 0
Accepted
time: 60ms
memory: 4096kb
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.144988346 319.828078817 381.389564952 746.180273168 963.421506922 1227.109204594 611.003273314 1002.920734655 943.708111653 1095.102734920 949.482490623 533.240096017 1153.170412385 911.857993330 468.369512244 789.797442405 704.298232312 599.641559600 575.420715651 44.407308287 889.404857194 862...
result:
ok 1400 numbers
Test #5:
score: 0
Accepted
time: 54ms
memory: 4096kb
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...
output:
3880.164042924 8564.951196592 7960.238187391 11875.364836501 3953.309752600 3297.173638133 9857.594534165 4272.579197628 7583.435171477 9198.171176924 11056.489723235 10480.684137975 8143.960952755 11173.842714125 11225.114787832 12495.086754401 335.335652742 4080.854934937 3303.325899756 8462.04242...
result:
ok 140 numbers
Test #6:
score: 0
Accepted
time: 61ms
memory: 4096kb
input:
15 92173 34960 85436 79002 67020 16430 77956 88069 10526 52318 63416 18293 13873 21386 41723 31777 89639 91343 48769 44631 41406 14388 52543 19309 89807 68272 22189 65756 16037 54219
output:
98580.239039069 116364.195953910 69004.531010652 117614.993504230 53366.373307543 66001.688652640 25491.589299218 52446.033768055 127979.271641934 66108.558613844 43834.591135312 55978.606002651 112811.183989000 69398.870718478 56541.005739198
result:
ok 15 numbers
Test #7:
score: 0
Accepted
time: 21ms
memory: 4096kb
input:
100 32 1357 71 18212 88 4150 5393 87 3137 50 18767 92 28 6442 29 11081 99 10064 54 17202 87 18903 12158 64 18148 4 7 6246 8293 51 14952 79 15079 87 3525 72 18014 61 22 12994 128 13 78 14983 19850 45 66 14787 8122 25 13318 21 18323 58 805 33 98 12252 14201 86 48 3265 14720 50 88 18800 9595 20 55 1484...
output:
1357.377250436 18212.138397234 4150.932907191 5393.701697350 3137.398444572 18767.225500857 6442.060850380 11081.037947774 10064.486921846 17202.084757378 18903.200205256 12158.168447591 18148.000440820 6246.003922509 8293.156817521 14952.208699721 15079.250976093 3525.735242471 18014.103280486 1299...
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 12ms
memory: 4096kb
input:
10 917 58363 44248 132 40874 823 397 22878 58217 320 353 200933 916 230431 775 68654 29128 744 789 24656
output:
58370.203511723 44248.196889817 40882.284733121 22881.444294450 58217.879461554 200933.310075756 230432.820615901 68658.374150572 29137.500235950 24668.620897813
result:
ok 10 numbers
Test #9:
score: 0
Accepted
time: 46ms
memory: 3968kb
input:
10 29426 81241 88905 209351 47528 40197 3341 95362 21284 82971 222683 93678 31532 19932 38832 87802 49584 60906 52331 10237
output:
86405.957879072 227446.565650045 62247.165341082 95420.507884836 85657.431067013 241584.946081083 37303.507180961 96005.809345060 78537.340749480 53322.881861355
result:
ok 10 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
2 49111 368792 490769 13502
output:
372047.617362348 490954.697874458
result:
ok 2 numbers
Test #11:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 732421 964572
output:
1211131.563631714
result:
ok found '1211131.563631714', expected '1211131.563631714', error '0.000000000'
Test #12:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 36078 937705
output:
938398.790018934
result:
ok found '938398.790018934', expected '938398.790018934', error '0.000000000'
Test #13:
score: 0
Accepted
time: 317ms
memory: 4096kb
input:
1 993066 148246
output:
1004070.195191551
result:
ok found '1004070.195191551', expected '1004070.195191551', error '0.000000000'
Test #14:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
1 42547 995544
output:
996452.760117107
result:
ok found '996452.760117107', expected '996452.760117107', error '0.000000000'
Test #15:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 994185 122012
output:
1001644.019783975
result:
ok found '1001644.019783975', expected '1001644.019783975', error '0.000000000'
Test #16:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 893299 999105
output:
1340221.587807777
result:
ok found '1340221.587807777', expected '1340221.587807777', error '0.000000000'
Test #17:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 999507 38171
output:
1000235.606389815
result:
ok found '1000235.606389815', expected '1000235.606389815', error '0.000000000'
Test #18:
score: 0
Accepted
time: 350ms
memory: 4096kb
input:
1 999994 372210
output:
1067018.408527238
result:
ok found '1067018.408527238', expected '1067018.408527238', error '0.000000000'
Test #19:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 999945 517082
output:
1125728.118929700
result:
ok found '1125728.118929700', expected '1125728.118929700', error '0.000000000'
Test #20:
score: 0
Accepted
time: 286ms
memory: 4096kb
input:
1 999495 444185
output:
1093750.688799783
result:
ok found '1093750.688799783', expected '1093750.688799783', error '0.000000000'
Test #21:
score: 0
Accepted
time: 351ms
memory: 4096kb
input:
1 999994 372210
output:
1067018.408527238
result:
ok found '1067018.408527238', expected '1067018.408527238', error '0.000000000'
Test #22:
score: 0
Accepted
time: 264ms
memory: 4096kb
input:
1 561402 999944
output:
1146760.746075658
result:
ok found '1146760.746075658', expected '1146760.746075658', error '0.000000000'
Test #23:
score: 0
Accepted
time: 157ms
memory: 4096kb
input:
1 999990 999999
output:
1414205.784212821
result:
ok found '1414205.784212821', expected '1414205.784212821', error '0.000000000'
Extra Test:
score: 0
Extra Test Passed