QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#309635#8030. Traveling in the Grid Worldalgotester#AC ✓295ms3864kbC++231.6kb2024-01-20 19:23:512024-01-20 19:23:51

Judging History

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

  • [2024-01-20 19:23:51]
  • 评测
  • 测评结果:AC
  • 用时:295ms
  • 内存:3864kb
  • [2024-01-20 19:23:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;
 
#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair

int gcd(int a, int b)
{
	return a == 0 ? b : gcd(b % a, a);
}

double dist(double a, double b)
{
	return sqrt(a*a + b*b);
}

double f(double best, int n, int m, int r, int c)
{
	if(r < 0 || n < r) return best;
	if(c < 0 || m < c) return best;
	if(r == 0 && c == 0) return best;
	if(r == n && c == m) return best;
	if(r == n - r && c == m - c) return best;
	if(gcd(r, c) != 1) return best;
	if(gcd(n - r, m - c) != 1) return best;
	return min(best, dist(r, c) + dist(n - r, m - c));
}

double f(int n, int m)
{
	if(gcd(n, m) == 1) return dist(n, m);
	int i, j;
	double inf = 1e47;
	double res = inf;
	FOR(i, 0, n + 1)
	{
		Int t = i;
		t *= m;
		t /= n;
		FOR(j, 0, 2)
		{
			int c = int(t) + j;
			res = f(res, n, m, i, c);
		}
	}
	FOR(i, 0, m + 1)
	{
		Int t = i;
		t *= n;
		t /= m;
		FOR(j, 0, 2)
		{
			int r = int(t) + j;
			res = f(res, n, m, r, i);
		}
	}
	assert(res != inf);
	return res;
}

void SolveTest(int test)
{
	int n, m;
	cin >> n >> m;
	cout << fixed << setprecision(14) << f(n, m) << endl;
}

int main()
{
	int T, t;
	T = 1;
	cin >> T;
	FOR(t, 0, T) 
	{
		//cerr << "Solving " << t << "/" << T << endl;
		SolveTest(t);
	}

	return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3772kb

input:

2
2 2
2 3

output:

3.23606797749979
3.60555127546399

result:

ok 2 numbers

Test #2:

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

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.41421356237310
2.23606797749979
3.16227766016838
4.12310562561766
5.09901951359278
6.08276253029822
7.07106781186548
8.06225774829855
9.05538513813742
10.04987562112089
11.04536101718726
12.04159457879230
13.03840481040530
14.03566884761820
15.03329637837291
2.23606797749979
3.23606797749979
3.605...

result:

ok 225 numbers

Test #3:

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

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.08331108738051
90.93404203047393
96.04688607571606
101.00000000000000
89.47066558375433
61.09828148156051
158.51815602817516
162.52076790367440
201.71762441591463
195.36888434696684
196.47137449375435
143.12581877495060
168.86977230990749
128.31601614763451
126.64912593384705
167.02694393420481
...

result:

ok 6000 numbers

Test #4:

score: 0
Accepted
time: 53ms
memory: 3780kb

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.14498834613960
319.82807881735459
381.38956495191178
746.18027316817438
963.42150692207406
1227.10920459427734
611.00327331365418
1002.92073465453893
943.70811165317423
1095.10273492036708
949.48249062318155
533.24009601679427
1153.17041238491720
911.85799333010186
468.36951224433898
789.7974424...

result:

ok 1400 numbers

Test #5:

score: 0
Accepted
time: 49ms
memory: 3772kb

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.16404292395873
8564.95119659184093
7960.23818739119270
11875.36483650095943
3953.30975259971228
3297.17363813312068
9857.59453416501674
4272.57919762758775
7583.43517147736929
9198.17117692424836
11056.48972323496128
10480.68413797497124
8143.96095275513198
11173.84271412480484
11225.1147878317...

result:

ok 140 numbers

Test #6:

score: 0
Accepted
time: 56ms
memory: 3684kb

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.23903906908527
116364.19595391015173
69004.53101065175724
117614.99350422972930
53366.37330754264258
66001.68865263978660
25491.58929921788877
52446.03376805532753
127979.27164193426142
66108.55861384363379
43834.59113531230105
55978.60600265068933
112811.18398899995373
69398.87071847783227
56...

result:

ok 15 numbers

Test #7:

score: 0
Accepted
time: 29ms
memory: 3744kb

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.37725043555974
18212.13839723386263
4150.93290719100150
5393.70169735034597
3137.39844457155277
18767.22550085654075
6442.06085038013225
11081.03794777366602
10064.48692184554420
17202.08475737753542
18903.20020525625296
12158.16844759111336
18148.00044081992382
6246.00392250917503
8293.1568175...

result:

ok 100 numbers

Test #8:

score: 0
Accepted
time: 8ms
memory: 3796kb

input:

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

output:

58370.20351172333903
44248.19688981687796
40882.28473312126152
22881.44429444959678
58217.87946155373356
200933.31007575622061
230432.82061590097146
68658.37415057249018
29137.50023595023958
24668.62089781267059

result:

ok 10 numbers

Test #9:

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

input:

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

output:

86405.95787907220074
227446.56565004450385
62247.16534108199994
95420.50788483573706
85657.43106701251236
241584.94608108344255
37303.50718096087803
96005.80934505994082
78537.34074948042689
53322.88186135479191

result:

ok 10 numbers

Test #10:

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

input:

2
49111 368792
490769 13502

output:

372047.61736234783893
490954.69787445763359

result:

ok 2 numbers

Test #11:

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

input:

1
732421 964572

output:

1211131.56363171385601

result:

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

Test #12:

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

input:

1
36078 937705

output:

938398.79001893429086

result:

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

Test #13:

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

input:

1
993066 148246

output:

1004070.19519155123271

result:

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

Test #14:

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

input:

1
42547 995544

output:

996452.76011710660532

result:

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

Test #15:

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

input:

1
994185 122012

output:

1001644.01978397497442

result:

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

Test #16:

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

input:

1
893299 999105

output:

1340221.58780777733773

result:

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

Test #17:

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

input:

1
999507 38171

output:

1000235.60638981452212

result:

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

Test #18:

score: 0
Accepted
time: 262ms
memory: 3832kb

input:

1
999994 372210

output:

1067018.40852723806165

result:

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

Test #19:

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

input:

1
999945 517082

output:

1125728.11892969976179

result:

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

Test #20:

score: 0
Accepted
time: 212ms
memory: 3776kb

input:

1
999495 444185

output:

1093750.68879978312179

result:

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

Test #21:

score: 0
Accepted
time: 262ms
memory: 3780kb

input:

1
999994 372210

output:

1067018.40852723806165

result:

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

Test #22:

score: 0
Accepted
time: 295ms
memory: 3784kb

input:

1
561402 999944

output:

1146760.74607565789483

result:

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

Test #23:

score: 0
Accepted
time: 41ms
memory: 3636kb

input:

1
999990 999999

output:

1414205.78421282093041

result:

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

Extra Test:

score: 0
Extra Test Passed