#include #include #include #include #include #include #include using namespace std; typedef complex POINT; typedef pair LINE; const double EPSIRON = 0.000000001; bool OnArea(int leftx, const LINE& l) { double x = (double)leftx + 0.5; if (l.first.real() < x && x < l.second.real() || l.second.real() < x && x < l.first.real()){ return true; } return false; } double CalcCrossPoint(const LINE& l, double x) { double x1 = l.first.real(); double y1 = l.first.imag(); double x2 = l.second.real(); double y2 = l.second.imag(); double a = (y2 - y1) / (x2 - x1); double b = y1 - a * x1; //cout << a * x + b << " " << endl; return a * x + b; } pair CalcCrossPointPair(const LINE& l, int leftx) { double y1 = CalcCrossPoint(l, (double)leftx); double y2 = CalcCrossPoint(l, (double)(leftx + 1)); if (y1 > y2){ swap(y1, y2); } //printf("(%.01lf,%.01lf)", y1, y2); return make_pair(y1, y2); } bool IsTate(const LINE& l) { return abs(l.first.real() - l.second.real()) < EPSIRON; } int GetSign(double f) { if (abs(f) < EPSIRON){ return 1; } if (f / abs(f) > 0.0){ return 1; } else { return -1; } } int CountArea(const vector& lines, int leftx) { vector > p; for (vector::const_iterator it = lines.begin(); it != lines.end(); ++it){ const LINE& line = *it; if (OnArea(leftx, line)){ p.push_back(CalcCrossPointPair(line, leftx)); } } sort(p.begin(), p.end()); if (p.empty()){ return 0; } //cout << endl; list > range; for (int i = 0; i < (int)p.size(); i += 2){ double ylow = p[i].first; double yhigh = p[i + 1].second; int begin, end; if (fmod(abs(ylow), 1.0) < EPSIRON || 1.0 - fmod(abs(ylow), 1.0) < EPSIRON){ begin = GetSign(ylow) * (int)(abs(ylow) + 0.5); } else { begin = (int)ylow; if (ylow < 0.0){ --begin; } } if (fmod(abs(yhigh), 1.0) < EPSIRON || 1.0 - fmod(abs(yhigh), 1.0) < EPSIRON){ end = GetSign(yhigh) * (int)(abs(yhigh) + 0.5); } else { end = (int)yhigh + 1; if (yhigh < 0.0){ --end; } } range.push_back(make_pair(begin, end)); } list >::iterator it1 = range.begin(); while (it1 != range.end()){ list >::iterator it2 = it1; ++it2; if (it2 == range.end()){ break; } if (it1->second > it2->first){ it1->second = max(it1->second, it2->second); range.erase(it2); } else { ++it1; } } int res = 0; for (list >::iterator it = range.begin(); it != range.end(); ++it){ //cout << "[" << it->first << "," << it->second << "]"; res += it->second - it->first; } //cout << endl; //if (!p.empty()){ //cout << "Count leftx:" << leftx << " line: " << p.size() //<< " area:" << res << endl; //} return res; } main() { int m; while (cin >> m && m){ vector lines; lines.reserve(m); POINT points[101]; for (int i = 0; i < m; ++i){ double x, y; cin >> x >> y; points[i] = POINT(x, y); } points[m] = points[0]; for (int i = 0; i < m; ++i){ LINE l = make_pair(points[i], points[i + 1]); if (IsTate(l)){ continue; } lines.push_back(l); } int answer = 0; for (int x = -2000; x < 2000; ++x){ answer += CountArea(lines, x); } cout << answer << endl; } }