#include #include #include int _field[300][300]; #define field(x,y) _field[(x)-150][(y)-150] #define i_n ((i + 1) % N) int _hrany[150][4]; #define hranax1(x) _hrany[x][0] #define hranax2(x) _hrany[x][1] #define hranay1(x) _hrany[x][2] #define hranay2(x) _hrany[x][3] typedef struct item { float x; int pm; } item_t; item_t tok[300]; int toks; int tmp1, tmp2, tmp3; double ftmp1, ftmp2, ftmp3; int fields, checkin; static int tokcmp(const void *a, const void *b); int main() { int N; int i, j, k; int proch; int seen; scanf("%d", &N); int p_x, p_y; int l_x, l_y; while (N != 0) { fields = 0; scanf("%d %d", &p_x, &p_y); for (i=1;i hranay2(i)) { tmp1 = hranax1(i); hranax1(i) = hranax2(i); hranax2(i) = tmp1; tmp1 = hranay1(i); hranay1(i) = hranay2(i); hranay2(i) = tmp1; } } // projdu vsechny radky for (i=-105;i<105;i++) { toks = 0; // pro vsechny hrany for (j=0; j i) continue; if (y2 < i+1) continue; ftmp1 = x1 + (i - y1) * (x2 - x1)/((double) y2 - y1); ftmp2 = x1 + (i + 1 - y1) * (x2 - x1)/((double) y2 - y1); if (ftmp1 > ftmp2) { ftmp3 = ftmp1; ftmp1 = ftmp2; ftmp2 = ftmp3; } ftmp1 = floor(ftmp1); ftmp2 = ceil(ftmp2); if (ftmp1 == ftmp2) add(ftmp1, 42); else { add (ftmp1, 1); add (ftmp2, -1); } // printf("r%d u%d: %lf -> %lf\n", i, j, ftmp1, ftmp2); #undef x1 #undef y1 #undef x2 #undef y2 } qsort(tok, toks, sizeof (item_t), tokcmp); j = 0; seen = 0; proch = 0; for (k=-105; k< 105; k++) { while (j < toks && tok[j].x == k) { switch (tok[j].pm) { case 1: proch++; seen++; break; case -1: proch--; break; case 42: seen++; break; } j++; } // printf("%d %d\n", seen, proch); if ((seen % 2 == 1) && (proch == 0)) fields++; } } printf("%d\n", fields); scanf("%d", &N); } } static int tokcmp(const void *a, const void *b) { return ((item_t *) a)->x - ((item_t *) b)->x; }