BEGIN Clrscr; Nhap; Chuanbi; Tinhslmien; GhiKQ; END..[r]
(1)Bài 7/1999 - Miền mặt phẳng chia đường thẳng (Dành cho học sinh THPT)
Program Bai7;
(* Tinh so giao diem cua n duong thang ko trung *) Uses Crt;
Const
fn = 'P7.INP'; fg = 'P7.OUT'; max = 100; exp = 0.0001; Var
a ,b ,c : array[1 max] of real; n : integer;
smien : integer; Procedure Nhap; Var
f : text; i : integer; Begin
Assign( f ,fn ); Reset( f ); Readln( f ,n );
For i := to n
Readln( f ,a[i] ,b[i] ,c[i] ); { ax + by = c } Close( f );
End;
(* -*) Procedure Chuanbi;
Begin smien := 1; End;
(* -*) Function Giaodiem( i ,j : integer;Var x ,y : real ) : boolean; Var
d ,dx ,dy :real; Begin
d := a[i] * b[j] - a[j] * b[i]; dx:= c[i] * b[j] - c[j] * b[i]; dy := a[i] * c[j] - a[j] * c[i]; If d <> then
begin x := dx / d; y := dy / d; end;
Giaodiem := d <> 0; End;
(2)Function Giatri( i : integer;x ,y : real ) : real; Begin
Giatri := a[i] * x + b[i] * y - c[i]; End;
(* -*) Function bang( a ,b : real ) : boolean;
Begin
bang := abs( a - b ) <= exp; End;
(* -*) Function Thoaman( i : integer;x ,y : real ) : boolean;
Var
ii : integer; Begin
Thoaman := false; For ii := to i -
If bang( Giatri( ii ,x ,y ) ,0 ) then exit;
Thoaman := true; End;
(* -*) Function Cattruoc( i : integer ) : integer;
Var
ii , gt : integer; x, y : real; Begin gt:= 0;
For ii := to i -
If Giaodiem( i ,ii ,x ,y ) then If Thoaman( ii ,x ,y ) then Inc( gt ); cattruoc := gt;
End;
(* -*) Procedure Tinhslmien;
Var i : integer; Begin
For i := to n
Inc( smien ,cattruoc( i ) + ); End;
(* -*) Procedure GhiKQ;
Begin
Writeln(So mien mat phang duoc chia la: ' ,smien ); End;
(3)