QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#447908#8785. Fake Coin and Lying ScaleslichenghanAC ✓200ms4240kbC++141.2kb2024-06-19 00:03:352024-06-19 00:03:36

Judging History

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

  • [2024-06-19 00:03:36]
  • 评测
  • 测评结果:AC
  • 用时:200ms
  • 内存:4240kb
  • [2024-06-19 00:03:35]
  • 提交

answer

#include <bits/stdc++.h>
#define dbg(...) (fprintf(stderr,##__VA_ARGS__),fflush(stderr))
#define dputs(str) dbg(str "\n")
using namespace std;

double add_ln(double x,double y){
	if(x>y) swap(x,y);
	if(x-y>=30) return x;
	return y+log(exp(x-y)+1);
}

double fact(int x){
	return (x+0.5)*log(x);
}

double binom(int u,int d){
	if(d==0||d==u) return 0;
	return fact(u)-fact(d)-fact(u-d)-1;
}

long long n,k;
void solve(){
	scanf("%lld%lld",&n,&k);
	if(k==0){
		printf("%.20lf\n",n*log(3));
		return;
	}
	double bot=log(3*k+1);
	if(k>=n) return (void) printf("%.20lf\n",bot);
	double ans=log(3)*n+bot;
	double div=0;
	if(1.5*k>=n){
		div=log(3)*n;
	}else{
		for(int i=0;i<=40&&i<=k;i++){
			div=add_ln(div,binom(n,k-i)+log(2)*(k-i));
		}
	}
	ans-=div;
	// printf("%.20lf %.20lf\n",bot,ans);
	printf("%.20lf\n",max(bot,ans));
}

void test(){
	auto exact_binom=[&](int n,int k){
		double ans=0;
		for(int i=n;i>=n-k+1;i--) ans+=log(i);
		for(int i=k;i>=1;i--) ans-=log(i);
		return ans;
	};
	// const int n=40,k=20;
	const int n=1e6,k=5e5;
	printf("%+.4lf\n",exact_binom(n,k)-binom(n,k));
}

int main(){
	// test(); return 0;
	int tc;
	scanf("%d",&tc);
	while(tc--){
		solve();
	}
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
100 0
100 1

output:

109.86122886681097554629
105.93924719644667220564

result:

ok q=0 (2 test cases)

Test #2:

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

input:

10000
32 6
45 98
67 57
35 70
29 3
22 81
59 12
48 16
63 69
99 36
60 36
32 47
73 91
81 30
7 7
71 57
38 60
35 19
92 40
3 17
21 71
54 62
95 67
60 50
10 20
19 80
64 73
10 21
70 97
84 3
26 22
38 47
37 38
31 91
11 37
73 17
75 98
8 74
73 60
87 10
94 48
35 73
18 14
88 25
61 54
39 59
100 90
70 98
73 21
92 11
...

output:

20.17550472840905939620
5.68697535633982020897
5.14749447681345273509
5.35185813347606664792
23.87554244816926285466
5.49716822529320214841
32.30953256311723009730
16.89647190708933521819
5.33753807970131788352
25.84965944883099098206
6.54868881371174893502
4.95582705760126085437
5.61312810638807047...

result:

ok q=0 (10000 test cases)

Test #3:

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

input:

1
10000 0

output:

10986.12288668109795253258

result:

ok q=0 (1 test case)

Test #4:

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

input:

1
10000 10

output:

10905.70314224009234749246

result:

ok q=0 (1 test case)

Test #5:

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

input:

1
10000 100

output:

10365.79243269461585441604

result:

ok q=0 (1 test case)

Test #6:

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

input:

1
100000 0

output:

109861.22886681098316330463

result:

ok q=0 (1 test case)

Test #7:

score: 0
Accepted
time: 2ms
memory: 4120kb

input:

1000
867 38
906 28
876 34
182 38
692 59
986 55
675 20
699 12
741 82
154 11
264 6
682 4
176 19
728 69
37 95
501 56
998 96
495 52
359 86
750 19
726 39
794 6
268 16
609 70
414 45
182 19
123 68
909 56
880 71
419 8
679 14
363 16
751 35
299 73
852 35
901 36
903 63
425 85
416 33
80 89
863 91
491 32
603 84
...

output:

777.67742305327146823402
858.09744631217154164915
802.37745033272483397013
87.66692411933394168955
525.80141522928352060262
840.98119062977195881103
644.19835861722071967961
704.77484816969160874578
508.03299522924714892724
127.58403606787584294580
262.05549168787490543764
726.18999142393033707776
1...

result:

ok q=0 (1000 test cases)

Test #8:

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

input:

1000
71 766
31 464
8 194
12 296
69 506
55 518
31 237
73 576
50 685
1 137
29 661
58 508
46 870
33 172
66 94
41 634
38 725
94 163
94 45
34 685
71 486
95 511
37 108
54 643
64 94
1 624
48 283
1 64
23 122
3 866
52 798
68 669
43 460
68 187
50 403
31 877
100 191
44 512
33 50
91 732
37 584
22 501
46 93
81 7...

output:

7.74022952476318160109
7.23921497377980571741
6.36818718635049219046
6.79009723551390464991
7.32580750259577317962
7.34923082461333443405
6.56807791141197583329
7.45529848568329089886
7.62851762657505538812
6.02102334934952665435
7.59287028784481776711
7.32974968904151236160
7.86748856869912849277
6...

result:

ok q=0 (1000 test cases)

Test #9:

score: 0
Accepted
time: 111ms
memory: 4100kb

input:

100000
448906 73251
858780 829062
380117 529011
219451 974416
390411 446812
457769 678634
440286 29979
663948 267273
623318 824172
557346 329036
2366 757990
279231 95725
394222 75586
671713 417299
997686 156089
462641 704003
267172 15563
115033 76151
271539 36507
909436 341831
97232 987703
780566 75...

output:

242700.25061139423632994294
14.72666291100904345512
14.27737742334962689483
14.88820622691749839817
14.10850623816470594818
14.52645001308146355257
353455.46327571361325681210
96659.54852849862072616816
14.72074721808731823103
7085.43977071030531078577
14.63703820035290092960
60920.18158061633585020...

result:

ok q=0 (100000 test cases)

Test #10:

score: 0
Accepted
time: 188ms
memory: 4196kb

input:

100000
740599 913
947030 8115
575926 9039
721122 7094
794424 8453
157723 6263
973352 1890
462079 302
333631 3870
435636 4238
572643 7448
775859 6119
343386 2778
486927 1883
880553 7918
878758 5150
274829 778
759586 5734
461205 6806
744940 1346
378522 4830
214767 1511
367452 9987
288068 9685
761467 1...

output:

805982.49377638322766870260
988105.07814472797326743603
579950.17814761877525597811
747487.36301121045835316181
820109.78931374230887740850
142607.87225431128172203898
1054350.19038093718700110912
504930.51533082791138440371
342767.90518702706322073936
451821.35474141570739448071
584224.606102523277...

result:

ok q=0 (100000 test cases)

Test #11:

score: 0
Accepted
time: 54ms
memory: 4196kb

input:

100000
3460 249080
4870 627106
7714 639325
6245 973410
5156 799724
2143 932101
3190 88015
5691 880401
4405 773261
157 516968
1022 535321
7679 193074
2293 754309
6302 607322
9422 65236
7327 352879
2188 417324
3181 532778
8804 165866
2433 321295
4829 557456
7228 613548
470 947610
2867 326654
1091 7711...

output:

13.52414303591172561880
14.44748368454757425638
14.46678102131282095399
14.88717328070450740540
14.69063465260236256427
14.84380910317801571807
12.48387860937424775898
14.78674543176452971238
14.65698463585982125323
14.25434918947683726742
14.28923475729737901929
13.26944282920997686404
14.632170107...

result:

ok q=0 (100000 test cases)

Test #12:

score: 0
Accepted
time: 110ms
memory: 4196kb

input:

100000
485911443 648621499
967545108 273118575
544774196 541753568
572826636 56596285
997351031 75012282
841305005 238445153
871651103 680174033
831928615 349267999
895576242 735170120
38669405 423897783
879163052 156607422
474161410 146955978
703868457 884260985
882781563 482183053
774752914 414027...

output:

21.38897218724784465849
297865547.59441471099853515625
21.20893407370613203966
405381382.26864337921142578125
777499095.82414042949676513672
257440440.77879035472869873047
21.43647158145904541016
105964410.15132963657379150391
21.51422477529918708683
20.96361519575657439418
445375781.679015278816223...

result:

ok q=0 (100000 test cases)

Test #13:

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

input:

100000
998709247 6662353
938409567 5496364
470262254 388552
44631553 8053900
263812189 8140673
570847244 3686835
143527865 6364614
630983298 5151426
508843717 9845212
529080317 4866307
229185417 7424168
870671276 2477533
922155225 4868463
286532330 7131107
5469824 6272182
112064124 9288326
871839242...

output:

1052557876.41213083267211914062
993406423.18275928497314453125
513220014.85424339771270751953
22380606.62413096427917480469
247854666.44696015119552612305
602319074.61338055133819580078
127217814.43167030811309814453
659736907.68618822097778320312
503607563.57506459951400756836
550220073.25466477870...

result:

ok q=0 (100000 test cases)

Test #14:

score: 0
Accepted
time: 61ms
memory: 4240kb

input:

100000
2388237 863104141
1949853 594471487
5788570 323905636
6626472 532884672
6478027 985480511
8713369 400770447
7877963 563355387
8572690 802705946
246447 691673591
1048191 39348128
9822372 87353076
4622806 985586908
3940664 689517333
7206000 907183324
7647553 126209541
9304319 816108273
3026286 ...

output:

21.67465820405449505870
21.30179560086173395916
20.69457507411961927346
21.19242787277673301105
21.80725219761950839370
20.90751165948626777435
21.24803351422751163113
21.60211129965743026560
21.45323700214522233409
18.58657125577328983468
19.38408110106205128886
21.80736015638240132830
21.450114682...

result:

ok q=0 (100000 test cases)

Test #15:

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

input:

100000
3230 990083111
447677 391972657
692146 408354973
191509 902573102
662501 450354073
721550 41375394
457751 109724688
636199 701346721
4329 135209393
7190 728002830
562092 480808431
608393 78791345
751611 613615532
576135 459945713
830181 180428675
549685 436319534
608642 828570290
40757 416064...

output:

21.81191173707909669588
20.88531493228940405515
20.92625967545723497665
21.71937253337443962664
21.02415694963822545560
18.63680921099919984840
19.61209724176822888353
21.46712522099328879222
19.82094748514536419748
21.50442778264202559058
21.08959176575065441739
19.28092600666911238250
21.333491409...

result:

ok q=0 (100000 test cases)

Test #16:

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

input:

100000
25834 61214455
26648 808954129
93315 645258548
40846 889138139
50931 688595112
83574 231579050
4476 298005500
10230 178645104
67274 582026639
45478 228216795
31799 640547396
76931 331956048
42831 764190687
32200 938076217
11303 774768820
48548 908303551
52646 376587760
30951 91507236
32097 76...

output:

19.02850620651732782562
21.60986506163011000581
21.38377393323840536254
21.70437545740151108475
21.44877629953504438731
20.35904413199341078666
20.61123479046185735797
20.09952402705059881782
21.28063906536671368031
20.34441888053407510029
21.37644596419053044656
20.71912542224711373251
21.552940195...

result:

ok q=0 (100000 test cases)

Test #17:

score: 0
Accepted
time: 194ms
memory: 4112kb

input:

100000
274227737 68346059
218685007 54356465
989024364 38654736
621112634 30460344
744276614 23921662
244777456 92571767
802238000 396401
867445410 73326922
915786289 8870270
283682509 84172313
874633287 75201041
511367562 84949073
634359016 56041772
732833967 55417420
693037815 93779223
439536157 2...

output:

99920321.21307414770126342773
79945807.49689087271690368652
896551040.40912818908691406250
539707003.67066419124603271484
695323400.88062870502471923828
42420667.06015351414680480957
877659783.90550231933593750000
650860090.90439224243164062500
949986390.21665835380554199219
80819166.983082115650177...

result:

ok q=0 (100000 test cases)

Test #18:

score: 0
Accepted
time: 194ms
memory: 4120kb

input:

100000
145675394 9644
868401983 5079
81959359 7252
221259510 4525
210940342 503
709938567 8322
313226886 2026
284975389 1034
961263243 1271
708878403 8424
147154537 1117
597142707 9049
49009960 8469
632841549 912
998250617 5932
107131683 9999
243110679 3650
921083825 3103
645636937 7805
803218474 41...

output:

159931663.18799510598182678223
953967307.07345938682556152344
89961615.26718021929264068604
243021911.38098418712615966797
231734299.58742049336433410645
779838670.97530245780944824219
344087281.40724360942840576172
313062773.48986345529556274414
1056036267.72607123851776123047
778672746.19592678546...

result:

ok q=0 (100000 test cases)

Test #19:

score: 0
Accepted
time: 193ms
memory: 4240kb

input:

100000
415903859 143863
726725861 220923
721402153 142794
636365369 56467
195687608 492519
244711303 612418
892437244 320712
965738323 66085
653139241 592706
2885567 920921
430945805 947767
493265196 74615
877041778 105313
477250612 324587
932782139 573227
651591411 492931
438774413 597150
816745072...

output:

455527059.66290909051895141602
796226817.58319723606109619141
791081850.30244100093841552734
698496398.67167019844055175781
211203946.76948988437652587891
264138079.23057189583778381348
977355968.51814544200897216797
1060226382.91457939147949218750
712391734.01027989387512207031
724793.4234833815135...

result:

ok q=0 (100000 test cases)

Test #20:

score: 0
Accepted
time: 197ms
memory: 4240kb

input:

100000
932735028 38475
303723723 37217
293643065 82693
53306635 90174
883367937 63149
414476477 62827
308746443 66010
319864936 52981
95584375 56035
201651629 95614
453621071 58910
638222297 35431
980668234 47930
725614760 41170
688105374 50896
958291243 76312
808245100 31656
617265859 68228
8643946...

output:

1024260600.21093809604644775391
333276403.21206974983215332031
321783884.94024211168289184570
57835244.72200749814510345459
969769151.02955591678619384766
454690074.14484709501266479492
338523082.03356993198394775391
350856629.78470075130462646484
104498327.80518926680088043213
220643283.62984427809...

result:

ok q=0 (100000 test cases)

Test #21:

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

input:

1
1000 1000000000

output:

21.82187812594785469855

result:

ok q=0 (1 test case)

Test #22:

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

input:

1
1 100000000

output:

19.51929303595380815750

result:

ok q=0 (1 test case)

Test #23:

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

input:

1
100 1000000000

output:

21.82187812594785469855

result:

ok q=0 (1 test case)

Test #24:

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

input:

1
1 1000000000

output:

21.82187812594785469855

result:

ok q=0 (1 test case)

Test #25:

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

input:

1
1000000000 1000000000

output:

21.82187812594785469855

result:

ok q=0 (1 test case)

Extra Test:

score: 0
Extra Test Passed