kien_coi_1997

1814.cpp

Jun 1st, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. //Written by RR
  2.  
  3. {$MODE OBJFPC}
  4.  
  5. uses math;
  6. const
  7. FINP = '';
  8. FOUT = '';
  9. MAXN = 100111;
  10. eps = 1e-9;
  11.  
  12. type
  13. point = record x,y:double; end;
  14. circle = record x,y,r:double; end;
  15.  
  16. var
  17. f1,f2 : text;
  18. test,n : longint;
  19. a : array[1..MAXN] of point;
  20. res : circle;
  21.  
  22. procedure openF;
  23. begin
  24. assign(f1,FINP); reset(f1);
  25. assign(f2,FOUT); rewrite(f2);
  26. end;
  27.  
  28. procedure closeF;
  29. begin
  30. close(f1);
  31. close(f2);
  32. end;
  33.  
  34. procedure inp;
  35. var
  36. i:longint;
  37. begin
  38. read(f1,n);
  39. for i:=1 to n do
  40. with a[i] do
  41. read(f1,x,y);
  42. end;
  43.  
  44. procedure update2(a,b:point);
  45. begin
  46. res.x:=(a.x+b.x)/2;
  47. res.y:=(a.y+b.y)/2;
  48. res.r:=sqr(a.x-res.x) + sqr(a.y-res.y);
  49. end;
  50.  
  51. procedure update3(a,b,c:point);
  52. var
  53. s,u,v:double;
  54. begin
  55. u:=(c.y-b.y)/2-(c.x-b.x)*(a.x-b.x)/2/(b.y-a.y);
  56. v:=(c.y-a.y)*(a.x-b.x)/(b.y-a.y)-(a.x-c.x);
  57. s:=u/v;
  58. res.x:=(a.x+c.x)/2+s*(c.y-a.y);
  59. res.y:=(a.y+c.y)/2+s*(a.x-c.x);
  60. res.r:=sqr(a.x-res.x)+sqr(a.y-res.y);
  61. end;
  62.  
  63. function isInside(a:point):boolean;
  64. begin
  65. exit( sqr(a.x-res.x) + sqr(a.y-res.y) < res.r+eps );
  66. end;
  67.  
  68. procedure solve;
  69. var
  70. i,j,k:longint;
  71. begin
  72. update2(a[1],a[2]);
  73. for i:=3 to n do
  74. if not isInside(a[i]) then
  75. begin
  76. update2(a[1],a[i]);
  77. for j:=1 to i-1 do
  78. if not isInside(a[j]) then
  79. begin
  80. update2(a[i],a[j]);
  81. for k:=1 to j-1 do
  82. if not isInside(a[k]) then
  83. update3(a[i],a[j],a[k]);
  84. end;
  85. end;
  86. writeln(f2,sqrt(res.r):0:2);
  87. writeln(f2,res.x:0:2,' ',res.y:0:2);
  88. end;
  89.  
  90. begin
  91. openF;
  92. read(f1,test);
  93. for test:=1 to test do
  94. begin
  95. inp;
  96. solve;
  97. end;
  98. closeF;
  99. end.
Advertisement
Add Comment
Please, Sign In to add comment