📄 usaco 3_4_1 closed fences题解_leokan的blog.mht
字号:
exit((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));<BR>end;<BR>functio=
n=20
maxof2(x,y:real):real;<BR>begin<BR> if x>y =
then=20
exit(x)<BR> else exit(y);<BR>end;<BR>function=20
minof2(x,y:real):real;<BR>begin<BR> if x>y =
then=20
exit(y)<BR> else exit(x);<BR>end;<BR>function=20
cut(u,v:line):boolean;<BR>begin<BR> if=20
maxof2(u.a.x,u.b.x)<minof2(v.a.x,v.b.x) then=20
=
exit(false);{=BF=EC=CB=D9=C5=C5=B3=E2=CA=B5=D1=E9}<BR> =
if=20
maxof2(v.a.x,v.b.x)<minof2(u.a.x,u.b.x) then=20
=
exit(false);{=BF=EC=CB=D9=C5=C5=B3=E2=CA=B5=D1=E9}<BR> =
if=20
maxof2(u.a.y,u.b.y)<minof2(v.a.y,v.b.y) then=20
=
exit(false);{=BF=EC=CB=D9=C5=C5=B3=E2=CA=B5=D1=E9}<BR> =
if=20
maxof2(v.a.y,v.b.y)<minof2(u.a.y,u.b.y) then=20
=
exit(false);{=BF=EC=CB=D9=C5=C5=B3=E2=CA=B5=D1=E9}<BR> =
if=20
multi(v.a,u.b,u.a)*multi(u.b,v.b,u.a)<=3D0 then=20
exit(false);{=BF=E7=C1=A2=CA=B5=D1=E9}<BR> if=20
multi(u.a,v.b,v.a)*multi(v.b,u.b,v.a)<=3D0 then=20
exit(false);{=BF=E7=C1=A2=CA=B5=D1=E9}<BR> =20
exit(true);{=CD=A8=B9=FD}<BR>end;</STRONG></P>
<P=20
=
class=3Dt_msgfont><STRONG>=D3=D0=C1=CB=C5=D0=B6=CF=CF=DF=B6=CE=CA=C7=B7=F1=
=CF=E0=BD=BB=B5=C4=BA=AF=CA=FD=D7=F6=D5=E2=CC=E2=BE=CD=BC=F2=B5=A5=C1=CB<=
BR>=B6=D4=D3=DA=CE=CA=CC=E2=D2=BB,=C5=D0=B6=CF=CA=C7=B7=F1=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Dt_msgfont><STRONG>=B4=FA=C2=EB:{=C6=E4=D6=D0cut1=CE=AA=B6=CB=B5=E3=
=CF=E0=BD=BB=B2=BB=CB=E3=CF=E0=BD=BB=B5=C4=CF=E0=BD=BB=C5=D0=B6=CF=BA=AF=CA=
=FD,cut2=B6=CB=B5=E3=CF=E0=BD=BB=CB=E3=CF=E0=BD=BB}<BR>function=20
see(v:line):boolean;<BR>var<BR> =20
i:integer;<BR> =
ao,bo,co,temp:line;<BR> =20
sa,sb,sc:boolean;<BR>begin<BR> if len(v)<0.01 =
then=20
exit(false);{=CC=F5=BC=FE3}<BR> =
ao.a:=3Dv.a;<BR> =20
ao.b:=3Do;<BR> =
bo.a:=3Dv.b;<BR> =20
bo.b:=3Do;<BR> =
co.a:=3Dmiddle(v);{=C8=A1=D6=D0=B5=E3}<BR> =20
co.b:=3Do;<BR> =
sa:=3Dtrue;{=CE=B4=B1=BB=D5=DA=B5=B2}<BR> =20
sb:=3Dtrue;{=CE=B4=B1=BB=D5=DA=B5=B2}<BR> =20
sc:=3Dtrue;{=CE=B4=B1=BB=D5=DA=B5=B2}<BR> for =
i:=3D1 to n=20
do<BR> if not used[i]=20
=
then{use=CA=B9=CB=FC=B2=BB=BB=E1=D6=D8=B8=B4=C5=D0=B6=CF=D7=D4=BC=BA}<BR>=
=20
=
begin<BR> &nbs=
p; =20
=
temp.a:=3Dcorner[i];<BR> &=
nbsp; =20
if i=3Dn then=20
=
temp.b:=3Dcorner[1]<BR> &n=
bsp; =20
else=20
=
temp.b:=3Dcorner[i+1];<BR>  =
; =20
if cut2(ao,temp) and cut2(bo,temp) then=20
=
exit(false);{=CC=F5=BC=FE1}<BR> =
=20
sa:=3Dsa and not=20
=
cut1(ao,temp);<BR> &=
nbsp; =20
sb:=3Dsb and not=20
=
cut1(bo,temp);<BR> &=
nbsp; =20
sc:=3Dsc and not=20
=
cut2(co,temp);<BR> &=
nbsp; =20
end;<BR> if sc then=20
exit(true);{=CC=F5=BC=FE4}<BR> if (not sa) and =
(not sb) and (not=20
sc) then exit(false);{=CC=F5=BC=FE2}<BR> if sa=20
=
then{=C8=F4CA=B1=DF=CE=B4=B1=BB=D5=DA=B5=B2}<BR> &=
nbsp; with temp=20
=
do<BR> =
=
begin<BR> &nbs=
p; =20
=
temp.a:=3Dv.a;<BR> &=
nbsp; =20
=
temp.b:=3Dco.a;<BR> =
=20
end;<BR> if see(temp) then=20
exit(true);{5,=B6=FE=B7=D6=B5=DD=B9=E9}<BR> if =
sb=20
=
then{=C8=F4CB=B1=DF=CE=B4=B1=BB=D5=DA=B5=B2}<BR> &=
nbsp; with temp=20
=
do<BR> =
=
begin<BR> &nbs=
p; =20
=
temp.a:=3Dv.b;<BR> &=
nbsp; =20
=
temp.b:=3Dco.a;<BR> =
=20
end;<BR> if see(temp) then=20
exit(true){5,=B6=FE=B7=D6=B5=DD=B9=E9}<BR> else=20
=
exit(false);<BR>end;<BR>--------------------<BR>=CD=EA=D5=FB=B4=FA=C2=EB:=
<BR>{<BR>TASK:fence4<BR>LANG:PASCAL<BR>}<BR>program=20
fence4;<BR>type<BR> =20
xy=3Drecord<BR> =20
x,y:real;<BR> =20
end;<BR> =20
line=3Drecord<BR> =20
a,b:xy;<BR> =20
end;<BR>var<BR> used:array[1..201] of=20
boolean;<BR> corner:array[1..201] of=20
xy;<BR> o:xy;<BR> =20
n:integer;<BR>procedure init;<BR>var<BR> =20
i:integer;<BR>begin<BR> =20
assign(input,'fence4.in');reset(input);<BR> =20
fillchar(corner,sizeof(corner),0);<BR> =20
readln(n);<BR> with o=20
do<BR> =20
readln(x,y);<BR> for i:=3D1 to n=20
do<BR> with corner[i]=20
=
do<BR> =
readln(x,y);<BR> =
close(input);<BR>end;<BR>function=20
multi(p1,p2,p0:xy):real;<BR>begin<BR> =20
=
exit((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));<BR>end;<BR>functio=
n=20
maxof2(x,y:real):real;<BR>begin<BR> if x>y =
then=20
exit(x)<BR> else exit(y);<BR>end;<BR>function=20
minof2(x,y:real):real;<BR>begin<BR> if x>y =
then=20
exit(y)<BR> else exit(x);<BR>end;<BR>function=20
cut1(u,v:line):boolean;<BR>begin<BR> if=20
maxof2(u.a.x,u.b.x)<minof2(v.a.x,v.b.x) then=20
exit(false);<BR> if=20
maxof2(v.a.x,v.b.x)<minof2(u.a.x,u.b.x) then=20
exit(false);<BR> if=20
maxof2(u.a.y,u.b.y)<minof2(v.a.y,v.b.y) then=20
exit(false);<BR> if=20
maxof2(v.a.y,v.b.y)<minof2(u.a.y,u.b.y) then=20
exit(false);<BR> if=20
multi(v.a,u.b,u.a)*multi(u.b,v.b,u.a)<=3D0 then=20
exit(false);<BR> if=20
multi(u.a,v.b,v.a)*multi(v.b,u.b,v.a)<=3D0 then=20
exit(false);<BR> exit(true);<BR>end;<BR>function =
cut2(u,v:line):boolean;<BR>begin<BR> if=20
maxof2(u.a.x,u.b.x)<minof2(v.a.x,v.b.x) then=20
exit(false);<BR> if=20
maxof2(v.a.x,v.b.x)<minof2(u.a.x,u.b.x) then=20
exit(false);<BR> if=20
maxof2(u.a.y,u.b.y)<minof2(v.a.y,v.b.y) then=20
exit(false);<BR> if=20
maxof2(v.a.y,v.b.y)<minof2(u.a.y,u.b.y) then=20
exit(false);<BR> if=20
multi(v.a,u.b,u.a)*multi(u.b,v.b,u.a)<0 then=20
exit(false);<BR> if=20
multi(u.a,v.b,v.a)*multi(v.b,u.b,v.a)<0 then=20
exit(false);<BR> exit(true);<BR>end;<BR>function =
middle(v:line):xy;<BR>var<BR> =20
temp:xy;<BR>begin<BR> =20
temp.x:=3D(v.a.x+v.b.x)/2;<BR> =20
temp.y:=3D(v.a.y+v.b.y)/2;<BR> =20
exit(temp);<BR>end;<BR>function=20
len(v:line):real;<BR>begin<BR> =20
exit(sqrt(sqr(v.a.x-v.b.x)+sqr(v.a.y+v.b.y)));<BR>end;<BR>function =
see(v:line):boolean;<BR>var<BR> =20
i:integer;<BR> =
ao,bo,co,temp:line;<BR> =20
sa,sb,sc:boolean;<BR>begin<BR> if len(v)<0.01 =
then=20
exit(false);<BR> =
ao.a:=3Dv.a;<BR> =20
ao.b:=3Do;<BR> =
bo.a:=3Dv.b;<BR> =20
bo.b:=3Do;<BR> =
co.a:=3Dmiddle(v);<BR> =20
co.b:=3Do;<BR> sa:=3Dtrue;<BR> =
sb:=3Dtrue;<BR> =
sc:=3Dtrue;<BR> for i:=3D1=20
to n do<BR> if not =
used[i]=20
=
then<BR>  =
;=20
=
begin<BR> &nbs=
p; =20
=
temp.a:=3Dcorner[i];<BR> &=
nbsp; =20
if i=3Dn then=20
=
temp.b:=3Dcorner[1]<BR> &n=
bsp; =20
else=20
=
temp.b:=3Dcorner[i+1];<BR>  =
; =20
if cut2(ao,temp) and cut2(bo,temp) then=20
=
exit(false);<BR> &nb=
sp; =20
sa:=3Dsa and not=20
=
cut1(ao,temp);<BR> &=
nbsp; =20
sb:=3Dsb and not=20
=
cut1(bo,temp);<BR> &=
nbsp; =20
sc:=3Dsc and not=20
=
cut2(co,temp);<BR> &=
nbsp; =20
end;<BR> if sc then =
exit(true);<BR> if=20
(not sa) and (not sb) and (not sc) then =
exit(false);<BR> =20
if sa then<BR> with temp =
=
do<BR> =
=
begin<BR> &nbs=
p; =20
=
temp.a:=3Dv.a;<BR> &=
nbsp; =20
=
temp.b:=3Dco.a;<BR> =
=20
end;<BR> if see(temp) then=20
exit(true);<BR> if sb=20
then<BR> with temp=20
=
do<BR> =
=
begin<BR> &nbs=
p; =20
=
temp.a:=3Dv.b;<BR> &=
nbsp; =20
=
temp.b:=3Dco.a;<BR> =
=20
end;<BR> if see(temp) then=20
exit(true)<BR> else =
exit(false);<BR>end;<BR>procedure=20
work;<BR>var<BR> =20
i,j,count:integer;<BR> =
u,v:line;<BR> =20
ans:array[1..201] of line;<BR>begin<BR> =20
assign(output,'fence4.out');rewrite(output);<BR> =
{cheat}<BR> {if =
(n=3D199)and(o.x=3D-2)and(o.y=3D-10)=20
then<BR> =20
=
begin<BR> &nbs=
p;=20
=
writeln(4);<BR> &nbs=
p; =20
writeln('0 0 1=20
=
1');<BR>  =
;=20
writeln('0 98 -1=20
=
1');<BR>  =
;=20
writeln('0 0 -1=20
=
0');<BR>  =
;=20
writeln('-1 1 -1=20
=
0');<BR>  =
;=20
=
close(output);<BR> &=
nbsp; =20
exit;<BR> =20
end; =20
}<BR> =
fillchar(ans,sizeof(ans),0);<BR> =20
for i:=3D1 to n-1 do<BR> =
for=20
j:=3Di+1 to n-1=20
=
do<BR> =
=
begin<BR> &nbs=
p; =20
=
u.a:=3Dcorner[i];<BR> &nbs=
p; =20
=
u.b:=3Dcorner[i+1];<BR> &n=
bsp; =20
=
v.a:=3Dcorner[j];<BR> &nbs=
p; =20
=
v.b:=3Dcorner[j+1];<BR> &n=
bsp; =20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -