QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771577#9348. Driverless Car飞带长队 (Xintong Fang, Jun Zheng, Haifeng Liu)AC ✓496ms4176kbC++178.0kb2024-11-22 14:21:152024-11-22 14:21:16

Judging History

This is the latest submission verdict.

  • [2024-11-22 14:21:16]
  • Judged
  • Verdict: AC
  • Time: 496ms
  • Memory: 4176kb
  • [2024-11-22 14:21:15]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using vec=complex<ld>;
const ld eps=1e-12;
ld dot(const vec &a,const vec &b){
	return real(a)*real(b)+imag(a)*imag(b);
}
ld cross(const vec &a,const vec &b){
	return dot(a,b*vec(0,-1));
}
ld dis2(const vec &a){
	return dot(a,a);
}
int sign(ld x){
	return (x>eps?1:(x<-eps?-1:0));
}
int T,xl,xr,yl,yr;
vec a[2],b[2];
void read(vec &a){
	int x,y;
	scanf("%d%d",&x,&y);
	a=vec(x,y);
}
vector<vec> common(vec a,vec b,vec x,vec y){
	ld s=cross(x-a,y-a),t=cross(y-b,x-b);
	if(sign(s+t)==0)return {};
	return {a*(t/(s+t))+b*(s/(s+t))};
}
vec arg(vec a){
	return a/abs(a);
}
pair<vec,vec> midline(vec a,vec b){
	return make_pair((a+b)/ld(2),arg(b-a)*vec(0,1));
}
bool chkin(vec x){
	return
		sign(real(x)-xl)>0&&sign(real(x)-xr)<0&&
		sign(imag(x)-yl)>0&&sign(imag(x)-yr)<0;
}
vec bnd[4];
ld calc1(vec st,vec arg){
	if(!chkin(st))return 0;
	ld len=INFINITY;
	for(int i=0;i<4;i++){
		for(vec x:common(bnd[i],bnd[(i+1)%4],st,st+arg)){
			if(sign(dot(x-st,arg))>=0)len=min(len,abs(x-st));
		}
	}
	return len;
}
ld calc2(vec a,vec b,vec arg){
	return abs(calc1(a,arg)-calc1(b,arg));
}
ld calc(ld d,ld a){
	ld w=sqrtl(a*a+4*d*d);
	return w*a/4/d+d*log(a+w);
}
vector<ld> solve(ld a,ld b,ld c){
	if(sign(a)==0){
		if(sign(b)==0)return {};
		else return {-c/b};
	}
	ld delta=b*b-4*a*c;
	if(sign(delta)<0)return {};
	delta=sqrtl(max<ld>(0,delta));
	return {(-b-delta)/2/a,(-b+delta)/2/a};
}
ld calc3(vec p1,vec p2,vec o,vec L,vec R){
	vec x=arg(p2-p1),y=x*vec(0,1);
	if(sign(dot(y,o-p1))<0)y=-y;
	ld d=dot(o-p1,y)/2,l=dot(L-o,x),r=dot(R-o,x);
	// debug(p1,p2,o,L,R,l,r);
	auto find=[&](ld p){
		return p*x+p*p/4/d*y+o-y*d;
	};
	if(l>r)swap(l,r),swap(L,R);
	vector<ld>t{l,r};
	for(int xt:{xl,xr}){
		for(ld p:solve(ld(1)/4/d*real(y),real(x),real(o-y*d)-xt)){
			if(sign(p-l)>0&&sign(p-r)<0)t.push_back(p);
		}
	}
	for(int yt:{yl,yr}){
		for(ld p:solve(ld(1)/4/d*imag(y),imag(x),imag(o-y*d)-yt)){
			if(sign(p-l)>0&&sign(p-r)<0)t.push_back(p);
		}
	}
	sort(all(t));
	// debug(t.size());
	ld res=0;
	for(int i=1;i<t.size();i++){
		ld tl=t[i-1],tr=t[i],mid=(tl+tr)/2;
		if(chkin(find(mid)))res+=abs(calc(d,tr)-calc(d,tl));
	}
	return res;
}
ld ans;
vec Common(vec a0,vec a1,vec b0,vec b1){
	vec i=arg((a1-a0)*vec(0,1)),j=arg((b1-b0)*vec(0,1));
	return (i+j)*(dot(i,a0)+dot(j,b0))/dis2(i+j);
}
void solve0(){
	vec mid=b[0]-cross(a[1]-a[0],b[0]-a[0])/abs(a[1]-a[0])/ld(2)*(arg(a[1]-a[0])*vec(0,1));
	auto solve=[&](vec a0,vec a1){
		vec o=Common(a0,a1,b[0],b[1]);
		vec half=arg(arg(a1-a0)+arg(b[1]-b[0])),las=mid;
		vec c0=common(o,o+half,b[0],b[0]+(b[1]-b[0])*vec(0,1))[0];
		auto [u0,u1]=midline(a1,b[0]);
		if(dot(u1,a1-a0)<0)u1=-u1;
		vec c1=common(u0,u0+u1,a1,a1+(a0-a1)*vec(0,1))[0];
		if(dot(c1-c0,a1-a0)>0){
			ans+=calc3(a0,a1,b[0],las,c0),las=c0;
			c0=common(o,o+half,b[1],b[1]+(b[0]-b[1])*vec(0,1))[0];
			c1=common(o,o+half,a1,a1+(a0-a1)*vec(0,1))[0];
			auto [v0,v1]=midline(a1,b[1]);
			if(dot(v1,a1-a0)<0)v1=-v1;
			if(dot(c1-c0,a1-a0)>0){
				ans+=calc2(las,c0,half),las=c0;
				c0=common(v0,v0+v1,a1,a1+(a0-a1)*vec(0,1))[0];
				ans+=calc3(a0,a1,b[1],las,c0),las=c0;
				ans+=calc1(las,v1);
			}else{
				ans+=calc2(las,c1,half),las=c1;
				c0=common(v0,v0+v1,b[1],b[1]+(b[0]-b[1])*vec(0,1))[0];
				ans+=calc3(b[0],b[1],a1,las,c0),las=c0;
				ans+=calc1(las,v1);
			}
		}else{
			ans+=calc3(a0,a1,b[0],las,c1),las=c1;
			if(sign(dot(b[1]-b[0],u1))<=0){
				ans+=calc1(las,u1);
			}else{
				c0=common(u0,u0+u1,b[0],b[0]+(b[1]-b[0])*vec(0,1))[0];
				ans+=calc2(las,c0,u1),las=c0;
				auto [v0,v1]=midline(a1,b[1]);
				if(dot(v1,a1-a0)<0)v1=-v1;
				c0=common(v0,v0+v1,b[1],b[1]+(b[0]-b[1])*vec(0,1))[0];
				ans+=calc3(b[0],b[1],a1,b[0],b[1]),las=c0;
				ans+=calc1(las,v1);
			}
		}
	};
	solve(a[0],a[1]);
	solve(a[1],a[0]);
}
void solve1(){
	vec mid=(a[0]+b[0])/ld(2);
	auto solve=[&](vec u){
		vec las=mid,a0=a[0],a1=a[1],b0=b[0],b1=b[1],c0,c1;
		int o0=sign(dot(a1-a0,u))>0,o1=sign(dot(b1-b0,u))>0;
		if(o0)c0=common(las,las+u,a0,a0+(a1-a0)*vec(0,1))[0];
		if(o1)c1=common(las,las+u,b0,b0+(b1-b0)*vec(0,1))[0];
		if(o0<o1||(o0==o1&&dot(c0-c1,u)>0))swap(o0,o1),swap(c0,c1),swap(a0,b0),swap(a1,b1);
		if(!o0)return ans+=calc1(las,u),void();
		ans+=calc2(las,c0,u),las=c0;
		auto [v0,v1]=midline(a1,b0);
		if(dot(v1,a1-a0)<0)v1=-v1;
		c0=common(v0,v0+v1,a1,a1+(a0-a1)*vec(0,1))[0],o0=1;
		vec o,half;
		if(sign(cross(b0-a0,a1-a0))==sign(cross(b1-b0,a1-a0))){
			o=Common(a0,a1,b0,b1),half=arg(arg(a1-a0)+arg(b1-b0));
			c1=common(o,o+half,b0,b0+(b1-b0)*vec(0,1))[0],o1=1;
		}else o1=0;
		if(o0>o1||(o0==o1&&dot(c1-c0,a1-a0)>0)){
			ans+=calc3(a0,a1,b0,las,c0),las=c0;
			if(!o1||sign(dot(v1,b1-b0))<=0){
				ans+=calc1(las,v1);
			}else{
				c0=common(v0,v0+v1,b0,b0+(b1-b0)*vec(0,1))[0];
				ans+=calc2(las,c0,v1),las=c0;
				auto [w0,w1]=midline(a1,b1);
				if(dot(w1,b1-b0)<0)w1=-w1;
				c0=common(w0,w0+w1,b1,b1+(b0-b1)*vec(0,1))[0];
				ans+=calc3(b0,b1,a1,las,c0),las=c0;
				ans+=calc1(las,w1);
			}
		}else{
			ans+=calc3(a0,a1,b0,las,c1),las=c1;
			c0=common(o,o+half,a1,a1+(a0-a1)*vec(0,1))[0];
			c1=common(o,o+half,b1,b1+(b0-b1)*vec(0,1))[0];
			if(dot(c0-c1,half)>0)swap(a0,b0),swap(a1,b1),swap(c0,c1);
			ans+=calc2(las,c0,half),las=c0;
			auto [w0,w1]=midline(a1,b1);
			if(dot(b1-b0,w1)<0)w1=-w1;
			c0=common(w0,w0+w1,b1,b1+(b0-b1)*vec(0,1))[0];
			ans+=calc3(b0,b1,a1,las,c0),las=c0;
			ans+=calc1(las,w1);
		}
	};
	solve(arg(b[0]-a[0])*vec(0,1));
	solve(arg(b[0]-a[0])*vec(0,-1));
}
void solve(vec a0,vec a1,vec b0,vec b1){
	vec u=arg(a1-a0);
	ans+=abs(a0-a1);
	b0+=a1-a0,a0=a1;
	vec las=(a0+b0)/ld(2);
	if(sign(abs(b0-b1))==0){
		ans+=calc1(las,u);
	}else{
		auto [v0,v1]=midline(a0,b1);
		if(dot(v1,b1-b0)<0)v1=-v1;
		vec c=common(v0,v0+v1,b1,b1+(b0-b1)*vec(0,1))[0];
		ans+=calc3(b0,b1,a0,las,c),las=c;
		ans+=calc1(las,v1);
	}
}
void solve2(){
	vec bm=(b[0]+b[1])/ld(2);
	vec am=bm-arg(a[1]-a[0])*vec(0,1)*(cross(a[1]-a[0],bm-a[0])/abs(a[0]-a[1]));
	solve(bm,b[1],am,a[1]);
	solve(bm,b[0],am,a[0]);
}
void solve3(){
	vec mid=(b[0]+a[1])/ld(2);
	vec am=mid-arg(a[1]-a[0])*vec(0,1)*(cross(a[1]-a[0],mid-a[0])/abs(a[0]-a[1]));
	vec bm=mid*ld(2)-am;
	solve(bm,b[0],am,a[0]);
	solve(am,a[1],bm,b[1]);
}
void work(){
	scanf("%d%d%d%d",&xl,&yl,&xr,&yr);
	bnd[0]=vec(xl,yl),bnd[1]=vec(xr,yl);
	bnd[2]=vec(xr,yr),bnd[3]=vec(xl,yr);
	read(a[0]),read(a[1]),read(b[0]),read(b[1]);
	int op=[&](){
		auto chk=[&](vec a0,vec a1,vec b0,vec b1){
			if(sign(cross(a1-a0,b0-a0))<=0)return 0;
			if(sign(cross(a1-a0,b0-a0)-cross(a1-a0,b1-a0))>=0)return 0;
			if(sign(dot(a1-a0,b0-a0))<=0)return 0;
			if(sign(dot(a0-a1,b0-a1))<=0)return 0;
			return 1;
		};
		for(int i:{0,1}){
			for(int j:{0,1}){
				if(chk(a[0],a[1],b[0],b[1]))return 0;
				swap(b[0],b[1]);
			}
			swap(a[0],a[1]);
		}
		swap(a[0],b[0]),swap(a[1],b[1]);
		for(int i:{0,1}){
			for(int j:{0,1}){
				if(chk(a[0],a[1],b[0],b[1]))return 0;
				swap(b[0],b[1]);
			}
			swap(a[0],a[1]);
		}
		if(sign(cross(a[1]-a[0],b[1]-b[0]))==0){
			auto cmp=[&](vec x,vec y){
				return sign(dot(y-x,a[1]-a[0]));
			};
			if(cmp(b[1],b[0])>0)swap(b[0],b[1]);
			if(cmp(b[0],a[0])>0)swap(a[0],b[0]),swap(a[1],b[1]);
			if(cmp(b[1],a[1])>=0)return 2;
			if(cmp(b[0],a[1])>=0)return 3;
		}
		tuple<ld,int,int>w[4];
		for(int i:{0,1})for(int j:{0,1}){
			w[i*2+j]={abs(a[i]-b[j]),i,j};
		}
		auto [d,i,j]=*min_element(w,w+4);
		if(i)swap(a[0],a[1]);
		if(j)swap(b[0],b[j]);
		return 1;
	}();
	ans=0;
	if(op==0)solve0();
	else if(op==1)solve1();
	else if(op==2)solve2();
	else solve3();
	printf("%.15Lf\n",ans);
}
int main(){
	for(scanf("%d",&T);T--;)work();
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
0 0 7 6
2 4 4 4
3 2 5 2

output:

7.552593593868681

result:

ok found '7.552593594', expected '7.552593594', error '0.000000000'

Test #2:

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

input:

100000
677 -490 687 -487
678 -488 681 -489
686 -488 679 -488
753 896 758 902
756 899 755 901
754 898 754 899
-786 69 -781 81
-784 75 -782 78
-784 71 -782 72
-879 110 -874 114
-878 111 -877 113
-877 112 -876 113
331 -97 340 -89
333 -92 337 -92
337 -90 332 -90
-26 -647 -22 -644
-23 -645 -24 -645
-25 -...

output:

5.756861965868625
6.008126807150700
5.355807136191452
4.629796182372582
9.158262808184446
5.124014274138828
3.000000000000000
15.771519826629556
5.989997145084788
5.761043816010222
4.335005245173137
4.117558803704217
4.421936941760152
8.164908200919798
4.995515334475031
3.080915944275558
5.952536893...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 438ms
memory: 3952kb

input:

100000
972 368 975 377
974 369 973 372
973 375 974 371
240 -78 247 -47
246 -53 246 -71
245 -72 241 -77
186 465 191 470
188 466 187 467
188 467 189 467
492 14 495 19
493 16 494 16
493 18 493 17
-846 741 -837 749
-842 746 -843 745
-844 747 -845 745
-974 -454 -957 -425
-959 -432 -963 -447
-970 -437 -97...

output:

4.531788164860569
8.394285829392128
6.197255957719672
3.390529756031286
8.583722447918406
30.328445143747419
8.295623131604798
7.081410190836008
4.902235045273875
5.388372692086863
18.241312597644944
7.411225744885154
4.390529756031286
5.264575510735209
12.219336404574532
12.333561641093523
8.305506...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 442ms
memory: 4048kb

input:

100000
-552 124 -546 142
-550 137 -550 135
-548 131 -550 128
-729 823 -693 829
-696 828 -708 824
-713 826 -726 825
-679 26 -630 48
-645 27 -635 42
-647 42 -666 46
45 462 58 504
50 497 49 496
49 463 55 485
-540 -897 -498 -877
-537 -893 -532 -896
-532 -887 -518 -878
-687 275 -660 284
-668 281 -681 278...

output:

6.597263092802142
6.445972112027350
34.491198425792631
14.578776019007242
29.334769983476428
10.153803915503490
13.390367513354031
44.677487089705047
4.197255957719675
7.003887809241696
24.112198192204927
29.470042199828046
5.783295140415156
23.118234649206359
3.000000000000000
53.271001906714060
21...

result:

ok 100000 numbers

Test #5:

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

input:

100000
-600 779 -580 835
-583 825 -599 821
-599 780 -590 804
568 374 591 401
572 395 589 384
569 389 569 379
408 -465 420 -412
414 -427 418 -433
419 -446 410 -427
-369 488 -251 542
-275 500 -334 528
-326 511 -349 505
328 704 452 713
372 706 421 705
336 711 422 712
-155 -404 -142 -360
-146 -382 -152 ...

output:

20.956624243169265
23.765584004187720
28.335988056931551
81.890356346162199
89.098587004223745
17.031401140148324
20.141224745292001
12.181950033706899
49.639585359763368
21.251285026715549
41.426994869678996
89.354325979121932
32.374396746056533
7.096556285347923
36.769187156110623
7.03892390364412...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 461ms
memory: 3968kb

input:

100000
573 365 736 461
581 379 630 396
594 408 688 387
-715 305 -708 378
-711 337 -713 324
-710 313 -710 331
145 610 165 670
147 613 155 646
152 657 161 647
96 -426 112 -282
98 -377 102 -368
111 -398 101 -417
-622 757 -542 815
-553 798 -569 762
-607 789 -561 800
631 -709 670 -484
653 -637 667 -690
6...

output:

93.416314091538983
17.299116787450781
27.424227296479232
18.755716541594084
77.775825841475396
100.383340475210173
11.984347301543359
84.747865307526622
14.013617944316641
71.554422394871648
21.830566757800210
51.238802008648300
150.148770223774970
13.263302499990845
183.951914104533263
82.251348302...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 465ms
memory: 4124kb

input:

100000
0 254 468 334
29 329 111 296
409 283 367 296
133 558 896 603
796 586 643 598
600 573 248 591
470 -730 508 -437
484 -669 487 -452
494 -582 502 -544
-727 -507 -181 -495
-684 -506 -351 -503
-213 -503 -458 -498
468 -427 917 -235
563 -242 759 -280
546 -262 794 -411
384 -383 642 -376
552 -381 412 -...

output:

80.000000000000000
52.052777227447904
91.723091381206568
125.795296750245629
407.071942603140106
50.617833556766972
37.909008039015950
3.003747659175118
161.272974800655851
31.255911872930277
8.071264882268011
6.004798081534466
47.551644899129934
64.541891395017390
64.666413328765820
248.44933873174...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 480ms
memory: 4048kb

input:

100000
-944 -991 971 974
935 -451 422 -218
492 -497 -499 -150
-401 -239 750 417
494 182 531 213
-297 -69 726 -57
-925 866 992 876
163 868 69 875
-685 874 -307 867
399 103 994 623
966 463 963 413
586 197 751 406
-438 429 166 840
-210 832 -50 642
120 764 149 688
-678 -996 984 886
905 376 947 -228
-568...

output:

2239.927092283399211
855.079774278914129
10.002263211526092
533.189630973896888
430.259439798004391
1918.569680998276120
1465.628914983455743
370.957679722161268
1309.535151770918095
159.805017589722339
1115.807140654610397
814.029980330130896
1625.166879787260669
1405.514001983331457
842.0984525531...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 495ms
memory: 3964kb

input:

100000
-1000 -994 995 965
-281 -337 -339 -661
-802 -162 -374 510
-871 -978 963 847
-571 -202 -582 209
600 -916 -623 -784
-996 -926 999 828
369 19 -719 686
933 -674 -830 -623
-824 -924 933 886
595 153 494 -700
-498 -293 120 -202
-929 -971 889 941
207 -650 482 -139
76 96 -144 427
-985 -956 966 942
-95...

output:

2409.601690262920341
2261.227663495230216
2118.709268421921750
2144.908426780604909
2449.457541446548844
2183.332907954270767
1370.972710561026615
1987.236097907446866
1664.595071706223066
2278.664545633755624
1917.832552490355019
1286.021595624886596
2643.008083093821016
2355.647459702141063
1792.3...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 496ms
memory: 4176kb

input:

100000
-997 -930 998 990
-620 -300 76 146
910 728 -945 566
-997 -985 995 999
-421 -792 -733 773
892 822 302 -315
-990 -996 999 996
-2 -570 981 -903
-800 635 -848 648
-976 -999 971 997
730 -154 -92 -982
-943 290 -944 -215
-981 -991 1000 990
-327 -631 817 -917
-876 -618 895 -371
-999 -994 998 999
628 ...

output:

2324.840542972298947
2080.749649872828474
2369.838444353460027
2279.062024716478707
1808.531966055308723
2012.840346707269134
2917.906467319363322
2024.607407014701308
2703.186569270827987
1929.995146508968144
1404.247807470386497
2179.977088348008934
2251.404266377483917
1886.699712976463190
1667.8...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed