img
Czech Technical University in Prague
Faculty of Mathematics and Physics, Charles University in Prague
Faculty of Electrical Engineering and Computer Science, Technical University of Ostrava
Faculty of Informatics and Information Technologies, Slovak University of Technology
acm
Faculty of Informatics, Masaryk University
cz
Faculty of Management Science and Informatics, University of Zilina
CTU Open Contest 2009
Arable Area
aa.c, aa.C, aa.java, aa.p
The prime minister has recently bought a piece of valuable agricultural land, which is situated
in a valley forming a regular grid of unit square fields. ACM would like to verify the transac-
tion, especially whether the price corresponds to the market value of the land, which is always
determined as the number of unit square fields fully contained in it.
Your task is to write a program that computes the market value. The piece of land forms a closed
polygon, whose vertices lie in the corners of unit fields.
For example, the polygon in the picture (it corresponds to the first scenario in Sample Input)
contains three square fields.
Input Specification
The input consists of several test scenarios. Each scenario starts with a line containing one
integer number N (3 N 100), the number of polygon vertices. Each of the following N
lines contains a pair of integers Xi and Yi, giving the coordinates of one vertex. The vertices
are listed in the order they appear along the boundary of the polygon. You may assume that
no coordinate will be less then -100 or more than 100 and that the boundary does not touch
or cross itself.
The last scenario is followed by a line containing single zero.
Output Specification
For each scenario, output one line with an integer number -- the number of unit squares that
are completely inside the polygon.
Sample Input
4
11
53
54
35
5
33
25
34
52
11
5
00
0 -50
-50 -51
-51 -50
-50 0
0
Output for Sample Input
3
1
2500