QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405199#8030. Traveling in the Grid WorldTomato_Fish#AC ✓211ms3888kbC++141.1kb2024-05-05 13:36:482024-05-05 13:36:54

Judging History

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

  • [2024-05-05 13:36:54]
  • 评测
  • 测评结果:AC
  • 用时:211ms
  • 内存:3888kb
  • [2024-05-05 13:36:48]
  • 提交

answer

#include<bits/stdc++.h>
#define pi (3.14159265358979323846)
using namespace std;

typedef long double db;
typedef long long ll;
const int mod=998244353; 
const int N=1e7+100;
const db eps=1e-8;

int mi(int x,int t){
	int d=1;
	while(t){
		if(t%2) d=(ll)d*x%mod;
		x=(ll)x*x%mod;t/=2;
	}
	return d;
}
int ni(int x) {return mi(x,mod-2);}

int f[N],fl[N],nf[N],Ni[N];

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

int main()
{
	
	int T;scanf("%d",&T);
	while(T--){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n<m) swap(n,m);
		if(gcd(n,m)==1){
			db t=sqrt((db)n*n+(db)m*m);
			printf("%.10Lf\n",t);
			continue;
		}
		db Ans=1e9;
		for(int i=1;i<=n;i++){
			int t=m*1.0*i/n;
			if(gcd(i,t)==1&&gcd(n-i,m-t)==1&&(ll)i*(m-t)!=(ll)t*(n-i)){
				db tt=sqrt((db)i*i+(db)t*t)+sqrt((db)(n-i)*(n-i)+(db)(m-t)*(m-t));
				Ans=min(Ans,tt);
			}
			if(t<m&&gcd(i,t+1)==1&&gcd(n-i,m-t-1)==1&&(ll)i*(m-t-1)!=(ll)(t+1)*(n-i)){
				db tt=sqrt((db)i*i+(db)(t+1)*(t+1))+sqrt((db)(n-i)*(n-i)+(db)(m-t-1)*(m-t-1));
				Ans=min(Ans,tt);
			}
		}
		printf("%.10Lf\n",Ans);
	}
	
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
2 2
2 3

output:

3.2360679775
3.6055512755

result:

ok 2 numbers

Test #2:

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

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.4142135624
2.2360679775
3.1622776602
4.1231056256
5.0990195136
6.0827625303
7.0710678119
8.0622577483
9.0553851381
10.0498756211
11.0453610172
12.0415945788
13.0384048104
14.0356688476
15.0332963784
2.2360679775
3.2360679775
3.6055512755
4.5764912225
5.3851648071
6.3591736031
7.2801098893
8.261297...

result:

ok 225 numbers

Test #3:

score: 0
Accepted
time: 24ms
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.0833110874
90.9340420305
96.0468860757
101.0000000000
89.4706655838
61.0982814816
158.5181560282
162.5207679037
201.7176244159
195.3688843470
196.4713744938
143.1258187750
168.8697723099
128.3160161476
126.6491259338
167.0269439342
161.8177987738
192.3382437270
175.4195698725
111.6109313643
169....

result:

ok 6000 numbers

Test #4:

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

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.1449883461
319.8280788174
381.3895649519
746.1802731682
963.4215069221
1227.1092045943
611.0032733137
1002.9207346545
943.7081116532
1095.1027349204
949.4824906232
533.2400960168
1153.1704123849
911.8579933301
468.3695122443
789.7974424051
704.2982323120
599.6415596004
575.4207156507
44.40730828...

result:

ok 1400 numbers

Test #5:

score: 0
Accepted
time: 30ms
memory: 3792kb

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.1640429240
8564.9511965918
7960.2381873912
11875.3648365010
3953.3097525997
3297.1736381331
9857.5945341650
4272.5791976276
7583.4351714774
9198.1711769242
11056.4897232350
10480.6841379750
8143.9609527551
11173.8427141248
11225.1147878318
12495.0867544007
335.3356527421
4080.8549349370
3303.32...

result:

ok 140 numbers

Test #6:

score: 0
Accepted
time: 40ms
memory: 3856kb

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.2390390691
116364.1959539102
69004.5310106518
117614.9935042297
53366.3733075426
66001.6886526398
25491.5892992179
52446.0337680553
127979.2716419343
66108.5586138436
43834.5911353123
55978.6060026507
112811.1839890000
69398.8707184778
56541.0057391978

result:

ok 15 numbers

Test #7:

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

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.3772504356
18212.1383972339
4150.9329071910
5393.7016973503
3137.3984445716
18767.2255008565
6442.0608503801
11081.0379477737
10064.4869218455
17202.0847573775
18903.2002052563
12158.1684475911
18148.0004408199
6246.0039225092
8293.1568175213
14952.2086997206
15079.2509760929
3525.7352424712
18...

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.2035117233
44248.1968898169
40882.2847331213
22881.4442944496
58217.8794615537
200933.3100757562
230432.8206159010
68658.3741505725
29137.5002359502
24668.6208978127

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 33ms
memory: 3888kb

input:

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

output:

86405.9578790722
227446.5656500445
62247.1653410820
95420.5078848357
85657.4310670125
241584.9460810835
37303.5071809609
96005.8093450599
78537.3407494804
53322.8818613548

result:

ok 10 numbers

Test #10:

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

input:

2
49111 368792
490769 13502

output:

372047.6173623479
490954.6978744577

result:

ok 2 numbers

Test #11:

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

input:

1
732421 964572

output:

1211131.5636317138

result:

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

Test #12:

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

input:

1
36078 937705

output:

938398.7900189343

result:

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

Test #13:

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

input:

1
993066 148246

output:

1004070.1951915513

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.7601171066

result:

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

Test #15:

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

input:

1
994185 122012

output:

1001644.0197839749

result:

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

Test #16:

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

input:

1
893299 999105

output:

1340221.5878077774

result:

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

Test #17:

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

input:

1
999507 38171

output:

1000235.6063898145

result:

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

Test #18:

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

input:

1
999994 372210

output:

1067018.4085272381

result:

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

Test #19:

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

input:

1
999945 517082

output:

1125728.1189296997

result:

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

Test #20:

score: 0
Accepted
time: 152ms
memory: 3792kb

input:

1
999495 444185

output:

1093750.6887997831

result:

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

Test #21:

score: 0
Accepted
time: 200ms
memory: 3792kb

input:

1
999994 372210

output:

1067018.4085272381

result:

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

Test #22:

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

input:

1
561402 999944

output:

1146760.7460756581

result:

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

Test #23:

score: 0
Accepted
time: 26ms
memory: 3872kb

input:

1
999990 999999

output:

1414205.7842128210

result:

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

Extra Test:

score: 0
Extra Test Passed