http://acm.pku.edu.cn/JudgeOnline/problem?id=2826
____________________________________________
A variety of circumstances to judge. If you use Pascal to output the answer, it is best to add an ESP, which is precision. Otherwise it is possible to output-0.00.
I think it is more standard to judge the line intersection and find out the intersection of the template. Though it's a bit lengthy.
____________________________________________
1 Program Stone;2 Constexp=1e-8;3 typecoord=Record4 x,y:real;5 End;6 varN,i:longint;7 O0,o1,o2,o3,o4,o5,o6,o7,o8,oi,ox:coord;8 Flag:boolean;9Function Cross (O1,o2,o3:coord): real; //Cross ProductTen begin Onecross:= (o2.x-o1.x) * (O3.Y-O1.Y)-(o3.x-o1.x) * (o2.y-o1.y); A End; - Function between (Y1,y2,y3:real): boolean; - Begin the if(y1-y2) * (Y1-Y3) <exp ThenBetween:=trueElsebetween:=false; - End; -Function Judgeintersect (O1,o2,o3,o4:coord): coord; //determine the intersection and find the intersection. - vars1,s2,s3,s4:real; + begin -s1:=Cross (O1,O2,O3); +s2:=Cross (O1,O2,O4); As3:=Cross (O3,O4,O1); ats4:=Cross (O3,O4,O2); -flag:=true; - if(S1*S2<-EXP) and(S3*S4<-EXP) Then - begin -Judgeintersect.x:= ((O3.X*S2)-(O4.X*S1))/(s2-s1); -Judgeintersect.y:= ((O3.Y*S2)-(O4.Y*S1))/(S2-S1); //using the canonical intersection formula to find the intersection. in exit; - End; to if(s1=0) and(Between (O3.Y,O1.Y,O2.Y)) Then beginJudgeintersect:=o3;exit;End; //a non-canonical intersection, where the intersection is an endpoint of a segment. + if(s2=0) and(Between (O4.Y,O1.Y,O2.Y)) Then beginJudgeintersect:=o4;exit;End; - if(s3=0) and(Between (O1.Y,O3.Y,O4.Y)) Then beginJudgeintersect:=o1;exit;End; the if(s4=0) and(Between (O2.Y,O3.Y,O4.Y)) Then beginJudgeintersect:=o2;exit;End; *Flag:=false; //otherwise it will not intersect. $ End;Panax Notoginseng Procedure work; - vars:real; the K:longint; + begin Ak:=0; the if(O1.Y-OI.Y>EXP) Then beginInc (k); o5:=o1;End; + if(O2.Y-OI.Y>EXP) Then beginInc (k); o5:=o2;End; - if(O3.Y-OI.Y>EXP) Then beginInc (k); O6:=o3;End; $ if(O4.Y-OI.Y>EXP) Then beginInc (k); O6:=o4;End; $ ifk<2 Then beginWriteln ('0.00'); exit;End; - ifO5.y-o6.y>exp Then beginO7:=o5;o5:=o6;o6:=o7;End; -o0.x:=oi.x;o0.y:=oi.y+ -; the if(Cross (OI,O0,O6) *cross (OI,O6,O5) >exp)) and(ABS (o6.x-oi.x)-abs (o5.x-oi.x)) >=-exp) Then - beginWriteln ('0.00'); exit;End;Wuyio7.x:=100000000; o7.y:=o5.y; theo8.x:=-100000000; o8.y:=o5.y; -ox:=Judgeintersect (o7,o8,o6,oi); Wus:=0; -o0.x:=0; o0.y:=0; Abouts:= (Cross (O0,o5,oi) +cross (O0,oi,ox) +cross (O0,OX,O5)) *0.5; $Writeln (ABS (s) +exp:0:2); //to add ESP - End; - Begin -Assign (input,'input1.in'); reset (input); AAssign (output,'Output.out'); rewrite (output); + READLN (n); the fori:=1 toN Do - begin $ readln (O1.X,O1.Y,O2.X,O2.Y,O3.X,O3.Y,O4.X,O4.Y); theOi:=judgeintersect (O1,O2,O3,O4); //find the intersection point. the if(ABS (o1.x-o2.x) <exp) and(ABS (O1.Y-O2.Y) <exp) Thenflag:=false; the if(ABS (o3.x-o4.x) <exp) and(ABS (O3.Y-O4.Y) <exp) Thenflag:=false; the ifFlag=false ThenWriteln ('0.00') - ElseWork ; in End; the close (input); close (output); the End. About the
poj2826 an easy problem?! 2012-01-11