Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.59 KB | None | 0 0
  1. program exam;
  2.  
  3. const l = 10000;
  4.  
  5. type // point structure
  6.  TPoint = record
  7.   X : integer;
  8.   Y : integer;
  9.  end;
  10.  
  11. type // circle structure
  12.  TCircle = record
  13.   Point : TPoint;
  14.   r : integer;
  15.  end;
  16.  
  17. var
  18.   i, j, n, r, s, maxp, maxc: integer;
  19.   arrOfPoints : array[1..l] of TPoint;
  20.   arrOfCircles : array[1..l] of TCircle;
  21.   matrixOfPoints : array[1..l,1..l] of integer;
  22.   matrixOfCrossCircles : array[1..l,1..l] of integer;
  23.  
  24. Procedure ReadPoints(var Point : TPoint);
  25.   begin
  26.     writeln('Введите Х');
  27.     readln(Point.X);
  28.     writeln('Введите Y');
  29.     readln(Point.Y);
  30.   end;  
  31.  
  32. Procedure ReadCircles(var Circle : TCircle; const r: integer);
  33.   begin
  34.     ReadPoints(Circle.Point);
  35.     Circle.r := r;
  36.   end;  
  37.  
  38. procedure PrintPoints(const Point : TPoint);
  39.   begin
  40.     writeln('Введенная точкa:');
  41.     write(Point.X:6,' ',Point.Y:6);
  42.   end;
  43.  
  44. procedure PrintCircles(const Circle : TCircle);
  45.   begin
  46.     writeln('Введенная окружность:');
  47.     PrintPoints(Circle.Point);
  48.     write(' ', Circle.r:6);
  49.     writeln();
  50.   end;
  51.  
  52. function IsPointInside(Point : Tpoint; Circle : TCircle) : integer;
  53.   begin
  54.     if (Sqrt(Sqr(Point.X - Circle.Point.X) + Sqr(Point.Y - Circle.Point.Y)) <= Circle.r) then
  55.       IsPointInside := 1
  56.     else
  57.       IsPointInside := 0;
  58.   end;
  59.  
  60. function IsCirclesCross(firstCircle : TCircle; secondCircle : TCircle) : integer;
  61.   begin
  62.     if (Sqrt(Sqr(firstCircle.Point.X - secondCircle.Point.X) + Sqr(firstCircle.Point.Y - secondCircle.Point.Y)) <= firstCircle.r + secondCircle.r)
  63.         and (Sqrt(Sqr(firstCircle.Point.X - secondCircle.Point.X) + Sqr(firstCircle.Point.Y - secondCircle.Point.Y)) > firstCircle.r) then
  64.       IsCirclesCross := 1
  65.     else
  66.       IsCirclesCross := 0;
  67.   end;
  68.  
  69. begin
  70.  
  71.   writeln('Введите кол-во точек');
  72.   readln(n);
  73.  
  74.   writeln('Введите радиус окружностей');
  75.   readln(r);
  76.  
  77.   writeln('Введите ', n, ' точки:');
  78.   for i:=1 to n do begin
  79.     ReadPoints(arrOfPoints[i]);
  80.   end;
  81.  
  82.   for i:=1 to n do begin
  83.     PrintPoints(arrOfPoints[i]);
  84.     writeln();
  85.   end;
  86.  
  87.   writeln('Введите ', n, ' окружности:');
  88.   for i:=1 to n do begin
  89.     ReadCircles(arrOfCircles[i], r);
  90.   end;
  91.  
  92.   for i:=1 to n do begin
  93.     PrintCircles(arrOfCircles[i]);
  94.     writeln();
  95.   end;
  96.  
  97.   maxp := integer.MinValue;
  98.  
  99.   for i:=1 to n do begin
  100.     s := 0;
  101.     for j:=1 to n do begin
  102.       s += IsPointInside(arrOfPoints[j], arrOfCircles[i]);
  103.     end;
  104.     writeln('В окружности номер ', i,' лежит ', s, ' точек.');
  105.     if(s > maxp) then begin
  106.       maxp := s;
  107.       maxc := i;
  108.     end;
  109.   end;
  110.  
  111.   for i:=1 to n do begin
  112.     for j:=1 to n do begin
  113.       matrixOfPoints[i, j] := IsPointInside(arrOfPoints[j], arrOfCircles[i]);
  114.     end;
  115.   end;
  116.  
  117.   writeln('Матрица отношений точек относительно окружностей');
  118.   for i:=1 to n do begin
  119.     for j:=1 to n do begin
  120.       write(matrixOfPoints[i, j] + ' ');
  121.     end;
  122.     writeln();
  123.   end;
  124.  
  125.   writeln('Больше всего точек в окружности номер ', maxc);
  126.  
  127.   for i:=1 to n do begin
  128.     for j:=1 to n do begin
  129.       matrixOfCrossCircles[i, j] := IsCirclesCross(arrOfCircles[j], arrOfCircles[i]);
  130.     end;
  131.   end;
  132.  
  133.   writeln('Матрица отношений окружностей относительно окружностей');
  134.   for i:=1 to n do begin
  135.     for j:=1 to n do begin
  136.       write(matrixOfCrossCircles[i, j] + ' ');
  137.     end;
  138.     writeln();
  139.   end;
  140. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement