Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define db long double
  4. #define x first
  5. #define y second
  6. #define mp make_pair
  7. #define pb push_back
  8. #define all(a) a.begin(), a.end()
  9.  
  10. using namespace std;
  11.  
  12. const db EPS = 1e-8;
  13. const db PI = acos(-1);
  14.  
  15. db get_angle(db a, db b, db c) {
  16. db top = a * a + b * b - c * c;
  17. db bot = 2 * a * b;
  18. return acos(top / bot);
  19. }
  20.  
  21. db area(db xa, db ya, db ra, db xb, db yb, db rb) {
  22. if (ra < rb) {
  23. swap(xa, xb);
  24. swap(ya, yb);
  25. swap(ra, rb);
  26. }
  27. db d = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
  28. if (d + EPS > ra + rb) {
  29. return 0;
  30. }
  31. if (ra + EPS > d + rb) {
  32. return PI * rb * rb;
  33. }
  34. db res = 0;
  35. db alp = 2 * get_angle(ra, d, rb);
  36. res += alp * ra * ra;
  37. res -= 0.5 * ra * ra * abs(sin(alp));
  38. cout << d << " " << ra << "\n";
  39. if (d + EPS > ra) {
  40. db beta = 2 * get_angle(rb, d, ra);
  41. res += beta * rb * rb;
  42. res -= 0.5 * rb * rb * abs(sin(beta));
  43. } else {
  44. db beta = 2 * PI - 2 * get_angle(d, rb, ra);
  45. res -= beta * rb * rb;
  46. res += 0.5 * rb * rb * abs(sin(beta));
  47. }
  48. return res;
  49. }
  50.  
  51. void solve() {
  52. int r, R;
  53. cin >> r >> R;
  54. int xa, ya, ra, Ra, xb, yb, rb, Rb;
  55. cin >> xa >> ya >> xb >> yb;
  56. ra = r, rb = r;
  57. Ra = R, Rb = R;
  58. db res = area(xa, ya, Ra, xb, yb, Rb);
  59. res -= area(xa, ya, ra, xb, yb, Rb);
  60. res -= area(xa, ya, Ra, xb, yb, rb);
  61. res += area(xa, ya, ra, xb, yb, rb);
  62. cout.precision(20);
  63. cout << res << "\n";
  64. }
  65.  
  66. int main(){
  67. #ifdef LOCAL
  68. freopen("M_input.txt", "r", stdin);
  69. //freopen("M_output.txt", "w", stdout);
  70. #endif
  71. ios_base::sync_with_stdio(0);
  72. cin.tie(0);
  73. int t;
  74. cin >> t;
  75. for (int i = 0; i < t; i++) {
  76. solve();
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement