Cod sursa(job #2106825)

Utilizator DruffbaumPopescu Vlad Druffbaum Data 16 ianuarie 2018 12:10:30
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <cstdio>

typedef long long i64;

struct Regl {
  int x1, y1, x2, y2;
};

static inline int max(int a, int b) {
  return a > b ? a : b;
}

static inline int min(int a, int b) {
  return a > b ? b : a;
}

i64 area(Regl a) {
  return 1LL * (a.x2 - a.x1) * (a.y2 - a.y1);
}

i64 per(Regl a) {
  return 2LL * (a.x2 - a.x1) + 2LL * (a.y2 - a.y1);
}

inline Regl inters(Regl a, Regl b) {
  Regl c;
  c.x1 = max(a.x1, b.x1);
  c.y1 = max(a.y1, b.y1);
  c.x2 = min(a.x2, b.x2);
  c.y2 = min(a.y2, b.y2);
  if (c.x2 < c.x1 || c.y2 < c.y1) {
    c = {0, 0, 0, 0};
  }
  return c;
}

int main() {
  Regl a, b, c;
  FILE *f = fopen("reuniune.in", "r");
  fscanf(f, "%d%d%d%d%d%d%d%d%d%d%d%d", &a.x1, &a.y1, &a.x2, &a.y2,
                                        &b.x1, &b.y1, &b.x2, &b.y2,
                                        &c.x1, &c.y1, &c.x2, &c.y2);
  fclose(f);
  f = fopen("reuniune.out", "w");
  fprintf(f, "%lld %lld\n", area(a) + area(b) + area(c) - area(inters(a, b)) - 
                            area(inters(a, c)) - area(inters(b, c)) + area(inters(a, inters(b, c))),
                            per(a) + per(b) + per(c) - per(inters(a, b)) -
                            per(inters(a, c)) - per(inters(b, c)) + per(inters(a, inters(b, c))));
  fclose(f);
  return 0;
}