Skip to content

Instantly share code, notes, and snippets.

@eduardodx
Created June 8, 2012 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardodx/2892862 to your computer and use it in GitHub Desktop.
Save eduardodx/2892862 to your computer and use it in GitHub Desktop.
SPOJ - Pesca
#include <stdio.h>
int main () {
int c[100][4], i, j, n, area_total, ax, ay;
area_total = 0;
// Limpando o vetor
for (i = 0; i < 100; i++) {
c[i][0] = 0;
c[i][1] = 0;
c[i][2] = 0;
c[i][3] = 0;
}
// Lendo as coordenadas
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &c[i][0], &c[i][1], &c[i][2], &c[i][3]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (
(c[i][0] >= c[j][0] && c[i][0] <= c[j][1] && c[i][2] >= c[j][2] && c[i][2] <= c[j][3]) ||
(c[i][0] >= c[j][0] && c[i][0] <= c[j][1] && c[i][3] >= c[j][2] && c[i][3] <= c[j][3]) ||
(c[i][1] >= c[j][0] && c[i][1] <= c[j][1] && c[i][2] >= c[j][2] && c[i][2] <= c[j][3]) ||
(c[i][1] >= c[j][0] && c[i][0] <= c[j][1] && c[i][3] >= c[j][2] && c[i][3] <= c[j][3])
) {
ax = c[j][1] - c[i][1];
ay = c[j][3] - c[i][3];
//c[i][0] = 0;
c[i][1] = 0;
//c[i][2] = 0;
c[i][3] = 0;
area_total = area_total - (ax * ay);
}
}
}
for (i = 0; i < n; i++) {
area_total = area_total + ( (c[i][1] - c[i][0]) * (c[i][3] - c[i][2]) );
}
printf("%d", area_total);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment