Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Const fi = 'Doidat.

inp';
fo = 'Doidat.out';
maxn = 10010;

Type Point = record


x,y:real;
end;

M1 = array [1..maxn] of real;


M2 = array [1..maxn] of Integer;

Var Tx,Ty:M1;
Ox,Oy:M2;
a,b,c,Sa,Sb,S:Real;
N,Sd:Integer;
f,g:Text;

Procedure DocDl;
Var i:Integer;
Begin
Assign(f,fi);
Reset(f);
Readln(f,N);
For i:=1 to n do
Readln(f,Ox[i],Oy[i]);
Close(f);
End;

Procedure LapPTDT(D1,D2:Point;Var a,b,c:Real);


Begin
a:=D2.y-D1.y;
b:=D1.x-D2.x;
c:=D1.y*D2.x-D1.x*D2.y;
End;

FuncTion GiaTri(D:Point):Real;
Begin
GiaTri:=A*D.x + B*D.y + C;
End;

FuncTion Cut(D1,D2:Point):Boolean;
Var F1,F2:Real;
Begin
F1:=GiaTri(D1);
F2:=GiaTri(D2);
If (F1=0) And (F2=0) Then
Begin
Cut:=False;
Exit;
End;
Cut:= F1*F2<=0;
End;

Procedure TimGiao(D1,D2:Point;var Gd:Point);


Var D,Dx,Dy:Real;
a1,b1,c1:Real;
Begin
LapPTDT(D1,D2,a1,b1,c1);
D:=a*b1-a1*b;
Dx:=b*c1-b1*c;
Dy:=c*a1-c1*a;
If D<>0 Then
Begin
Gd.x:=Dx/D;
Gd.y:=Dy/D;
End;
End;

Procedure ChuanBi;
Var D1,Dn:Point;
Begin
SA:=0;
SB:=0;
D1.x:=Ox[1];
D1.y:=Oy[1];
Dn.x:=Ox[N];
Dn.y:=Oy[N];
LapPTDT(D1,Dn,a,b,c);
End;

Procedure TinhDienTich;
Var i:Integer;
Begin
S:=0;
Tx[Sd+1]:=Tx[1];
Ty[Sd+1]:=Ty[1];
For i:=1 To Sd Do
S:=S+(Ty[i]+Ty[i+1])*(Tx[i]-Tx[i+1]);

S:=Abs(S)/2;
End;

Procedure XacDinhMien(Var TT:Integer);


Var i:Integer;
Begin
For i:=2 to Sd-1 do
If A*Tx[i] + B*Ty[i] + C <>0 Then
If A*Tx[i] + B*Ty[i] + C >0 Then TT:=2
Else TT:=1;
End;

Procedure XulyDaGiac;
Var TT,i,j:Integer;
Begin
TinhDienTich;
XacDinhMien(TT);
If TT=2 Then SA:=SA+S
Else
If TT=1 Then SB:=SB+S;
End;

Procedure Tinh;
Var i,j:Integer;
D1,D2,Gd:Point;
Begin
Tx[1]:=Ox[1];
Ty[1]:=Oy[1];
SD:=1;
For i:=2 to N-1 do
Begin
Inc(Sd);
Tx[Sd]:=Ox[i];
Ty[Sd]:=Oy[i];

D1.x:=Ox[i];
D1.y:=Oy[i];
D2.x:=Ox[i+1];
D2.y:=Oy[i+1];

If Cut(D1,D2) then
Begin
TimGiao(D1,D2,Gd);
Inc(Sd);
Tx[Sd]:=Gd.x;
Ty[Sd]:=Gd.y;

XulyDaGiac;

Sd:=1;
Tx[1]:=Gd.x;
Ty[1]:=Gd.y;

End;
End;

Inc(Sd);
Tx[Sd]:=Ox[n];
Ty[Sd]:=Oy[n];
XulyDaGiac;
End;

Procedure Ghikq;
Begin
Assign(g,fo);
Rewrite(g);
Writeln(G,Sa:0:4);
Writeln(G,Sb:0:4);
Close(g);
End;

Begin
Docdl;
ChuanBi;
Tinh;
Ghikq;
End.

You might also like