fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define el '\n'
  4.  
  5. const long double PI = acosl(-1);
  6. const long double PI2 = acosl(-1)*2;
  7.  
  8. # define point complex<long double>
  9. # define X real()
  10. # define Y imag()
  11. #define ld long double
  12. #define int long long
  13. long double dot(point a, point b){
  14. return (conj(a) * b).X;
  15. }
  16. long double cross(point a, point b){
  17. return (conj(a) * b).Y;
  18. }
  19. point cinP(){
  20. double a,b; cin >> a >> b;
  21. return point(a,b);
  22. }
  23. constexpr long double eps = 1e-8L;
  24.  
  25. bool iseq(ld a, ld b){
  26. return abs(a-b) < eps;
  27. }
  28.  
  29. point a,b;
  30. bool iseq(point a, point b){
  31. return (iseq(a.X, b.X) and iseq(a.Y, b.Y));
  32. }
  33. # define cfix(k) cout << fixed << setprecision(k) <<
  34. void solve(){
  35. long double r1,r2; cin >> r1;
  36. b = cinP(); cin >> r2;
  37. if(r2 > r1){swap(r1,r2); swap(a,b);}
  38. point ab = b-a;
  39. long double d = fabs(ab);
  40. if(d + r2 - r1 < -eps or d - r1 - r2 > eps){
  41. cout << "NO INTERSECTION" << el;
  42. return;
  43. }
  44. if(iseq(a,b) and iseq(r1, r2)){
  45. if(r1 < eps)cfix(3) a << el;
  46. else
  47. cout << "THE CIRCLES ARE THE SAME" << el;
  48. return;
  49. }
  50. long double th = (-r2 * r2 + d * d + r1 * r1) / (2*d*r1);
  51. th = acosl(th);
  52. if(::isnan(th))th = 0;
  53. point ans1 = ab / d * r1;
  54. point ans2 = ans1 * polar((ld)1, th);
  55. ans1 *= polar((ld)1, -th);
  56. ans1 += a;
  57. ans2 += a;
  58. if(ans2.X - ans1.X < -eps){
  59. swap(ans2, ans1);
  60. }else if(iseq(ans1.X, ans2.X) and ans2.Y - ans1.Y < -eps)swap(ans1, ans2);
  61.  
  62. if(abs(ans1.X) < 1e-3) ans1 = point(0, ans1.Y);
  63. if(abs(ans2.X) < 1e-3) ans2 = point(0, ans2.Y);
  64. if(abs(ans2.Y) < 1e-3) ans2 = point(ans2.X, 0);
  65. if(abs(ans1.Y) < 1e-3) ans1 = point(ans1.X, 0);
  66.  
  67. cfix(3) ans1;
  68. if(!iseq(ans1, ans2))cfix(3) ans2;
  69. cout << el;
  70.  
  71. }
  72.  
  73.  
  74.  
  75. signed main() {
  76. ios_base::sync_with_stdio(false); cin.tie(nullptr);
  77.  
  78. // freopen("intersec1.in", "r", stdin);
  79. // freopen("intersec1.out", "w", stdout);
  80. #ifndef ONLINE_JUDGE
  81. freopen("input.txt", "r", stdin);
  82. freopen("output.txt", "w", stdout);
  83. freopen("error.txt", "w", stderr);
  84. #endif
  85.  
  86. int t=1;
  87. // cin >> t;
  88. double x,y;
  89. while(cin >> x >> y){
  90. a = point(x,y);
  91. solve();
  92. }
  93. }
  94.  
  95. /*
  96.  
  97.  
  98. */
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty