QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645434#8030. Traveling in the Grid WorldATM12345AC ✓407ms3960kbC++171.2kb2024-10-16 18:21:302024-10-16 18:21:30

Judging History

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

  • [2024-10-16 18:21:30]
  • 评测
  • 测评结果:AC
  • 用时:407ms
  • 内存:3960kb
  • [2024-10-16 18:21:30]
  • 提交

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;

int n, m;

bool check(int x, int y) {
	return __gcd(x, y) == 1 && __gcd(n - x, m - 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) == 1) {
		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;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3960kb

input:

2
2 2
2 3

output:

3.23606797749978969641
3.60555127546398929313

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 3904kb

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.41421356237309504876
2.23606797749978969641
3.16227766016837933197
4.12310562561766054965
5.09901951359278482988
6.08276253029821968891
7.07106781186547524382
8.06225774829854965279
9.05538513813741662625
10.04987562112089027021
11.04536101718726077460
12.04159457879229548020
13.038404810405297429...

result:

ok 225 numbers

Test #3:

score: 0
Accepted
time: 48ms
memory: 3848kb

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.08331108738051114238
90.93404203047393406095
96.04688607571605211272
101.00000000000000000000
89.47066558375432136774
61.09828148156051041973
158.51815602817515615808
162.52076790367439068641
201.71762441591463477231
195.36888434696684103964
196.47137449375437200094
143.12581877495059416716
168....

result:

ok 6000 numbers

Test #4:

score: 0
Accepted
time: 67ms
memory: 3808kb

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.14498834613964928231
319.82807881735462157691
381.38956495191181822468
746.18027316817447791575
963.42150692207406215140
1227.10920459427733852920
611.00327331365418798148
1002.92073465453888780896
943.70811165317425178722
1095.10273492036707299047
949.48249062318152891038
533.240096016794295985...

result:

ok 1400 numbers

Test #5:

score: 0
Accepted
time: 60ms
memory: 3912kb

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.16404292395864672471
8564.95119659184047566924
7960.23818739119290466277
11875.36483650095905062472
3953.30975259971249324842
3297.17363813312082587714
9857.59453416501606071165
4272.57919762758756965226
7583.43517147736946348857
9198.17117692424769526127
11056.48972323496106540119
10480.684137...

result:

ok 140 numbers

Test #6:

score: 0
Accepted
time: 67ms
memory: 3940kb

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.23903906908258676367
116364.19595391015290886116
69004.53101065175766848370
117614.99350422972327123716
53366.37330754264404575338
66001.68865263978986490656
25491.58929921788929107151
52446.03376805533041959961
127979.27164193426522587060
66108.55861384363899446726
43834.59113531230457638799
...

result:

ok 15 numbers

Test #7:

score: 0
Accepted
time: 42ms
memory: 3956kb

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.37725043555964266062
18212.13839723386244351389
4150.93290719100173546963
5393.70169735034568114784
3137.39844457155298051987
18767.22550085653976914557
6442.06085038013184984607
11081.03794777366512391836
10064.48692184554433293187
17202.08475737753389900320
18903.20020525625447760376
12158.16...

result:

ok 100 numbers

Test #8:

score: 0
Accepted
time: 9ms
memory: 3940kb

input:

10
917 58363
44248 132
40874 823
397 22878
58217 320
353 200933
916 230431
775 68654
29128 744
789 24656

output:

58370.20351172334228451177
44248.19688981687798445819
40882.28473312126424588087
22881.44429444959665431725
58217.87946155373323620097
200933.31007575622975025453
230432.82061590098064129961
68658.37415057248499294928
29137.50023595024018518984
24668.62089781267038723911

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 60ms
memory: 3884kb

input:

10
29426 81241
88905 209351
47528 40197
3341 95362
21284 82971
222683 93678
31532 19932
38832 87802
49584 60906
52331 10237

output:

86405.95787907220463353042
227446.56565004449413436305
62247.16534108199854458121
95420.50788483574194742687
85657.43106701251053891610
241584.94608108345458674648
37303.50718096088144548617
96005.80934505994778760396
78537.34074948043479480475
53322.88186135479305960416

result:

ok 10 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

2
49111 368792
490769 13502

output:

372047.61736234785354326959
490954.69787445765922484497

result:

ok 2 numbers

Test #11:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

1
732421 964572

output:

1211131.56363171379450704990

result:

ok found '1211131.563631714', expected '1211131.563631714', error '0.000000000'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

1
36078 937705

output:

938398.79001893432746328472

result:

ok found '938398.790018934', expected '938398.790018934', error '0.000000000'

Test #13:

score: 0
Accepted
time: 245ms
memory: 3924kb

input:

1
993066 148246

output:

1004070.19519155133616550302

result:

ok found '1004070.195191551', expected '1004070.195191551', error '0.000000000'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

1
42547 995544

output:

996452.76011710660520748206

result:

ok found '996452.760117107', expected '996452.760117107', error '0.000000000'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

1
994185 122012

output:

1001644.01978397494946193547

result:

ok found '1001644.019783975', expected '1001644.019783975', error '0.000000000'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

1
893299 999105

output:

1340221.58780777740457779146

result:

ok found '1340221.587807777', expected '1340221.587807777', error '0.000000000'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

1
999507 38171

output:

1000235.60638981453928408882

result:

ok found '1000235.606389815', expected '1000235.606389815', error '0.000000000'

Test #18:

score: 0
Accepted
time: 317ms
memory: 3912kb

input:

1
999994 372210

output:

1067018.40852723810917268565

result:

ok found '1067018.408527238', expected '1067018.408527238', error '0.000000000'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

1
999945 517082

output:

1125728.11892969965026622958

result:

ok found '1125728.118929700', expected '1125728.118929700', error '0.000000000'

Test #20:

score: 0
Accepted
time: 239ms
memory: 3940kb

input:

1
999495 444185

output:

1093750.68879978311076683894

result:

ok found '1093750.688799783', expected '1093750.688799783', error '0.000000000'

Test #21:

score: 0
Accepted
time: 316ms
memory: 3820kb

input:

1
999994 372210

output:

1067018.40852723810917268565

result:

ok found '1067018.408527238', expected '1067018.408527238', error '0.000000000'

Test #22:

score: 0
Accepted
time: 407ms
memory: 3960kb

input:

1
561402 999944

output:

1146760.74607565810242704174

result:

ok found '1146760.746075658', expected '1146760.746075658', error '0.000000000'

Test #23:

score: 0
Accepted
time: 87ms
memory: 3816kb

input:

1
999990 999999

output:

1414205.78421282098781830427

result:

ok found '1414205.784212821', expected '1414205.784212821', error '0.000000000'

Extra Test:

score: 0
Extra Test Passed