fork download
  1. /*
  2.   Mongy wrote this shit
  3. */
  4.  
  5. #include <bits/stdc++.h>
  6.  
  7.  
  8. using namespace std;
  9. #define ll long long
  10. #define ld long double
  11. #define nl cout << '\n'
  12. #define pri(n) cout<<fixed<<setprecision(n)
  13. #define d5l_arr(arr, n) for(int i = 0 ; i < n ; i ++)cin >> arr[i]
  14. #define all(arr) arr.begin(), arr.end()
  15.  
  16. //#pragma GCC optimize("O3,unroll-loops")
  17. //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  18.  
  19. void m4_htgeb_tle_kda_ya3ny() {
  20. cin.tie(0);
  21. cin.sync_with_stdio(0);
  22. cout.tie(0);
  23. cout.sync_with_stdio(0);
  24. }
  25.  
  26. const int N = 1e6 + 1, inf = 1e9 + 10;
  27. const ll mod = 1e9 + 7, infl = 1e18 + 10;
  28.  
  29. #define pt pair<int, int>
  30. #define x first
  31. #define y second
  32. #define T double
  33. #define pd pair<T, T>
  34.  
  35. pt operator-(pt a, pt b){return {a.x - b.x, a.y - b.y }; }
  36. ll cross(pt a, pt b){ return a.x * b.y - a.y * b.x ; }
  37. ld cross(pd a, pd b){ return a.x * b.y - a.y * b.x ; }
  38. ll orient(pt a, pt b, pt c){return cross(a - b, c - b);}
  39. pd operator/(pt a, T f){ return {(T)a.x / f, (T)a.y / f}; }
  40. pt operator*(pt a, ll f){ return {a.x * f, a.y * f}; }
  41.  
  42. bool properInter(pt a, pt b, pt c, pt d, pd &out) {
  43. double oa = orient(c,d,a),
  44. ob = orient(c,d,b),
  45. oc = orient(a,b,c),
  46. od = orient(a,b,d);
  47. // Proper intersection exists iff opposite signs
  48. if (oa*ob < 0 && oc*od < 0) {out = (a*ob - b*oa) / (ob-oa); return true;}
  49. return false;
  50. }
  51.  
  52. int orientation(pd a, pd b, pd c) {
  53. double v = a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y);
  54. if (v < 0) return -1; // clockwise
  55. if (v > 0) return +1; // counter-clockwise
  56. return 0;
  57. }
  58.  
  59. bool cw(pd a, pd b, pd c, bool include_collinear) {
  60. int o = orientation(a, b, c);
  61. return o < 0 || (include_collinear && o == 0);
  62. }
  63. bool collinear(pd a, pd b, pd c) { return orientation(a, b, c) == 0; }
  64.  
  65. void convex_hull(vector<pd>& a, bool include_collinear = false) {
  66. pd p0 = *min_element(a.begin(), a.end(), [](pd a, pd b) {
  67. return make_pair(a.y, a.x) < make_pair(b.y, b.x);
  68. });
  69. sort(a.begin(), a.end(), [&p0](const pd& a, const pd& b) {
  70. int o = orientation(p0, a, b);
  71. if (o == 0)
  72. return (p0.x-a.x)*(p0.x-a.x) + (p0.y-a.y)*(p0.y-a.y)
  73. < (p0.x-b.x)*(p0.x-b.x) + (p0.y-b.y)*(p0.y-b.y);
  74. return o < 0;
  75. });
  76. if (include_collinear) {
  77. int i = (int)a.size()-1;
  78. while (i >= 0 && collinear(p0, a[i], a.back())) i--;
  79. reverse(a.begin()+i+1, a.end());
  80. }
  81.  
  82. vector<pd> st;
  83. for (int i = 0; i < (int)a.size(); i++) {
  84. while (st.size() > 1 && !cw(st[st.size()-2], st.back(), a[i], include_collinear))
  85. st.pop_back();
  86. st.push_back(a[i]);
  87. }
  88.  
  89. if (include_collinear == false && st.size() == 2 && st[0] == st[1])
  90. st.pop_back();
  91.  
  92. a = st;
  93. }
  94.  
  95.  
  96. bool above(pt a, pt p) { return p.y >= a.y;}
  97.  
  98. bool crossesRay(pt a, pt p, pt q) {return (above(a,q) - above(a,p)) * orient(a,p,q) > 0;}
  99.  
  100. bool inPolygon(vector<pt> p, pt a, bool strict = true) {
  101. int numCrossings = 0;
  102. for (int i = 0, n = p.size(); i < n; i++) {
  103. numCrossings += crossesRay(a, p[i], p[(i+1)%n]); }
  104. return numCrossings & 1;
  105. }
  106.  
  107. void solveCase() {
  108. int n, m;
  109. cin >> n >> m;
  110. vector<pt > a(n), b(m);
  111. for (auto &p: a) cin >> p.x >> p.y;
  112. for (auto &p: b) cin >> p.x >> p.y;
  113. vector<pd > arr;
  114. for (int i = 0; i < n; i++) {
  115. for (int j = 0; j < m; j++) {
  116. pt x = a[i], y = a[(i + 1) % n], u = b[j], v = b[(j + 1) % m];
  117. pd out;
  118. bool inter = properInter(x, y, u, v, out);
  119. if (inter) arr.push_back(out);
  120. }
  121. }
  122.  
  123. for(auto p: a){if (inPolygon(b, p)) arr.push_back(p);}
  124. for(auto p: b){if (inPolygon(a, p)) arr.push_back(p);}
  125.  
  126. if (arr.size() <= 2){ return cout << 0.0000, void(); }
  127. convex_hull(arr, false);
  128. n = (int)arr.size();
  129. ld ans = 0;
  130. for(int i = 0; i < n; i ++){
  131. ans += cross(arr[i], arr[(i + 1) % n]);
  132. }
  133. cout << fabs(ans) * .5;
  134. }
  135.  
  136.  
  137. signed main() {
  138. m4_htgeb_tle_kda_ya3ny();
  139. int test = 1;
  140. cin >> test;
  141. pri(4);
  142. for (int i = 1; i <= test; ++i) {
  143. solveCase();
  144. nl;
  145. }
  146. return 0;
  147. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:5: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
Main.java:9: error: illegal character: '#'
#define ll long long
^
Main.java:9: error: class, interface, or enum expected
#define ll long long
        ^
Main.java:10: error: illegal character: '#'
#define ld long double
^
Main.java:11: error: illegal character: '#'
#define nl cout << '\n'
^
Main.java:12: error: illegal character: '#'
#define pri(n) cout<<fixed<<setprecision(n)
^
Main.java:13: error: illegal character: '#'
#define d5l_arr(arr, n) for(int i = 0 ; i < n ; i ++)cin >> arr[i]
^
Main.java:13: error: class, interface, or enum expected
#define d5l_arr(arr, n) for(int i = 0 ; i < n ; i ++)cin >> arr[i]
                                        ^
Main.java:13: error: class, interface, or enum expected
#define d5l_arr(arr, n) for(int i = 0 ; i < n ; i ++)cin >> arr[i]
                                                ^
Main.java:14: error: illegal character: '#'
#define all(arr) arr.begin(), arr.end()
^
Main.java:21: error: class, interface, or enum expected
    cin.sync_with_stdio(0);
    ^
Main.java:22: error: class, interface, or enum expected
    cout.tie(0);
    ^
Main.java:23: error: class, interface, or enum expected
    cout.sync_with_stdio(0);
    ^
Main.java:24: error: class, interface, or enum expected
}
^
Main.java:27: error: class, interface, or enum expected
const ll mod = 1e9 + 7, infl = 1e18 + 10;
^
Main.java:29: error: illegal character: '#'
#define pt pair<int, int>
^
Main.java:29: error: class, interface, or enum expected
#define pt pair<int, int>
        ^
Main.java:30: error: illegal character: '#'
#define x first
^
Main.java:31: error: illegal character: '#'
#define y second
^
Main.java:32: error: illegal character: '#'
#define T double
^
Main.java:33: error: illegal character: '#'
#define pd pair<T, T>
^
Main.java:35: error: class, interface, or enum expected
pt operator-(pt a, pt b){return {a.x - b.x, a.y - b.y }; }
                                                         ^
Main.java:36: error: class, interface, or enum expected
ll cross(pt a, pt b){ return  a.x * b.y - a.y * b.x ; }
                                                      ^
Main.java:37: error: class, interface, or enum expected
ld cross(pd a, pd b){ return  a.x * b.y - a.y * b.x ; }
                                                      ^
Main.java:38: error: class, interface, or enum expected
ll orient(pt a, pt b, pt c){return cross(a - b, c - b);}
                                                       ^
Main.java:39: error: class, interface, or enum expected
pd operator/(pt a, T f){ return {(T)a.x / f, (T)a.y / f}; }
                                                          ^
Main.java:40: error: class, interface, or enum expected
pt operator*(pt a, ll f){ return {a.x * f, a.y * f}; }
                                                     ^
Main.java:48: error: class, interface, or enum expected
    if (oa*ob < 0 && oc*od < 0) {out = (a*ob - b*oa) / (ob-oa); return true;}
    ^
Main.java:48: error: class, interface, or enum expected
    if (oa*ob < 0 && oc*od < 0) {out = (a*ob - b*oa) / (ob-oa); return true;}
                                                                ^
Main.java:48: error: class, interface, or enum expected
    if (oa*ob < 0 && oc*od < 0) {out = (a*ob - b*oa) / (ob-oa); return true;}
                                                                            ^
Main.java:50: error: class, interface, or enum expected
}
^
Main.java:54: error: class, interface, or enum expected
    if (v < 0) return -1; // clockwise
    ^
Main.java:55: error: class, interface, or enum expected
    if (v > 0) return +1; // counter-clockwise
    ^
Main.java:56: error: class, interface, or enum expected
    return 0;
    ^
Main.java:57: error: class, interface, or enum expected
}
^
Main.java:61: error: class, interface, or enum expected
    return o < 0 || (include_collinear && o == 0);
    ^
Main.java:62: error: class, interface, or enum expected
}
^
Main.java:63: error: class, interface, or enum expected
bool collinear(pd a, pd b, pd c) { return orientation(a, b, c) == 0; }
                                                                     ^
Main.java:68: error: class, interface, or enum expected
    });
    ^
Main.java:69: error: class, interface, or enum expected
    sort(a.begin(), a.end(), [&p0](const pd& a, const pd& b) {
    ^
Main.java:71: error: class, interface, or enum expected
        if (o == 0)
        ^
Main.java:74: error: class, interface, or enum expected
        return o < 0;
        ^
Main.java:75: error: class, interface, or enum expected
    });
    ^
Main.java:76: error: class, interface, or enum expected
    if (include_collinear) {
    ^
Main.java:78: error: class, interface, or enum expected
        while (i >= 0 && collinear(p0, a[i], a.back())) i--;
        ^
Main.java:79: error: class, interface, or enum expected
        reverse(a.begin()+i+1, a.end());
        ^
Main.java:80: error: class, interface, or enum expected
    }
    ^
Main.java:83: error: class, interface, or enum expected
    for (int i = 0; i < (int)a.size(); i++) {
    ^
Main.java:83: error: class, interface, or enum expected
    for (int i = 0; i < (int)a.size(); i++) {
                    ^
Main.java:83: error: class, interface, or enum expected
    for (int i = 0; i < (int)a.size(); i++) {
                                       ^
Main.java:86: error: class, interface, or enum expected
        st.push_back(a[i]);
        ^
Main.java:87: error: class, interface, or enum expected
    }
    ^
Main.java:92: error: class, interface, or enum expected
    a = st;
    ^
Main.java:93: error: class, interface, or enum expected
}
^
Main.java:96: error: class, interface, or enum expected
bool above(pt a, pt p) { return p.y >= a.y;}
                                           ^
Main.java:98: error: class, interface, or enum expected
bool crossesRay(pt a, pt p, pt q) {return (above(a,q) - above(a,p)) * orient(a,p,q) > 0;}
                                                                                        ^
Main.java:102: error: class, interface, or enum expected
    for (int i = 0, n = p.size(); i < n; i++) {
    ^
Main.java:102: error: class, interface, or enum expected
    for (int i = 0, n = p.size(); i < n; i++) {
                                  ^
Main.java:102: error: class, interface, or enum expected
    for (int i = 0, n = p.size(); i < n; i++) {
                                         ^
Main.java:103: error: class, interface, or enum expected
        numCrossings += crossesRay(a, p[i], p[(i+1)%n]); }
                                                         ^
Main.java:105: error: class, interface, or enum expected
}
^
Main.java:109: error: class, interface, or enum expected
    cin >> n >> m;
    ^
Main.java:110: error: class, interface, or enum expected
    vector<pt > a(n), b(m);
    ^
Main.java:111: error: class, interface, or enum expected
    for (auto &p: a) cin >> p.x >> p.y;
    ^
Main.java:112: error: class, interface, or enum expected
    for (auto &p: b) cin >> p.x >> p.y;
    ^
Main.java:113: error: class, interface, or enum expected
    vector<pd > arr;
    ^
Main.java:114: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
    ^
Main.java:114: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                    ^
Main.java:114: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                           ^
Main.java:115: error: class, interface, or enum expected
        for (int j = 0; j < m; j++) {
                        ^
Main.java:115: error: class, interface, or enum expected
        for (int j = 0; j < m; j++) {
                               ^
Main.java:117: error: class, interface, or enum expected
            pd out;
            ^
Main.java:118: error: class, interface, or enum expected
            bool inter = properInter(x, y, u, v, out);
            ^
Main.java:119: error: class, interface, or enum expected
            if (inter) arr.push_back(out);
            ^
Main.java:120: error: class, interface, or enum expected
        }
        ^
Main.java:123: error: class, interface, or enum expected
    for(auto p: a){if (inPolygon(b, p)) arr.push_back(p);}
                                                         ^
Main.java:124: error: class, interface, or enum expected
    for(auto p: b){if (inPolygon(a, p)) arr.push_back(p);}
                                                         ^
Main.java:126: error: class, interface, or enum expected
    if (arr.size() <= 2){ return cout << 0.0000, void(); }
                                                         ^
Main.java:128: error: class, interface, or enum expected
    n = (int)arr.size();
    ^
Main.java:129: error: class, interface, or enum expected
    ld ans = 0;
    ^
Main.java:130: error: class, interface, or enum expected
    for(int i = 0; i < n; i ++){
    ^
Main.java:130: error: class, interface, or enum expected
    for(int i = 0; i < n; i ++){
                   ^
Main.java:130: error: class, interface, or enum expected
    for(int i = 0; i < n; i ++){
                          ^
Main.java:132: error: class, interface, or enum expected
    }
    ^
Main.java:134: error: class, interface, or enum expected
}
^
Main.java:139: error: class, interface, or enum expected
    int test = 1;
    ^
Main.java:140: error: class, interface, or enum expected
    cin >> test;
    ^
Main.java:141: error: class, interface, or enum expected
    pri(4);
    ^
Main.java:142: error: class, interface, or enum expected
    for (int i = 1; i <= test; ++i) {
    ^
Main.java:142: error: class, interface, or enum expected
    for (int i = 1; i <= test; ++i) {
                    ^
Main.java:142: error: class, interface, or enum expected
    for (int i = 1; i <= test; ++i) {
                               ^
Main.java:144: error: class, interface, or enum expected
        nl;
        ^
Main.java:145: error: class, interface, or enum expected
    }
    ^
Main.java:147: error: class, interface, or enum expected
}
^
95 errors
stdout
Standard output is empty