fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. struct point{int x;int y;};
  5. struct rect{point a;point b;};
  6. rect getrect(point a, point b, rect c){
  7. if(a.x > b.x)swap(a.x,b.x);
  8. if(a.y > b.y)swap(a.y,b.y);
  9. c.a = a;
  10. c.b = b;
  11. return c;
  12. }
  13. rect getrekt(rect c){
  14. point a,b;
  15. cin >> a.x >> a.y >> b.x >> b.y;
  16. return getrect(a,b,c);
  17. }
  18. int area(rect sq){return (sq.b.x - sq.a.x) * (sq.b.y - sq.a.y);}
  19.  
  20. rect cross(rect l,rect r){
  21. rect cr;
  22. point a1,b1;
  23. a1.x = ((l.a.x > r.b.x or r.a.x>l.b.x)?0:max(l.a.x,r.a.x));
  24. a1.y = ((l.a.y > r.b.y or r.a.y>l.b.y)?0:max(l.a.y,r.a.y));
  25. b1.x = ((l.a.x > r.b.x or r.a.x>l.b.x)?0:min(l.b.x,r.b.x));
  26. b1.y = ((l.a.y > r.b.y or r.a.y>l.b.y)?0:min(l.b.y,r.b.y));
  27. return getrect(a1,b1,cr);
  28. }
  29. int farea(rect *q){
  30. return area(q[0]) + area(q[1]) + area(q[2]) - area(cross(q[0],q[1])) - area(cross(q[0],q[2])) - area(cross(q[2],q[1])) + area(cross(q[0],cross(q[1],q[2])));
  31. }
  32. int main() {
  33. rect *q = new rect [3];
  34. for(int i = 0;i < 3;i++)q[i] = getrekt(q[i]);
  35. cout<<farea(q);
  36. }
Success #stdin #stdout 0s 15232KB
stdin
-8 5 3 6
24 0 17 1
-100 0 5 1
stdout
123