CF67E.Save the City!

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In the town of Aalam-Aara (meaning the Light of the Earth), previously there was no crime, no criminals but as the time progressed, sins started creeping into the hearts of once righteous people. Seeking solution to the problem, some of the elders found that as long as the corrupted part of population was kept away from the uncorrupted part, the crimes could be stopped. So, they are trying to set up a compound where they can keep the corrupted people. To ensure that the criminals don't escape the compound, a watchtower needs to be set up, so that they can be watched.

Since the people of Aalam-Aara aren't very rich, they met up with a merchant from some rich town who agreed to sell them a land-plot which has already a straight line fence ABAB along which a few points are set up where they can put up a watchtower. Your task is to help them find out the number of points on that fence where the tower can be put up, so that all the criminals can be watched from there. Only one watchtower can be set up. A criminal is watchable from the watchtower if the line of visibility from the watchtower to him doesn't cross the plot-edges at any point between him and the tower i.e. as shown in figure 1 below, points XX , YY , CC and AA are visible from point BB but the points EE and DD are not.

Figure 1 Figure 2 Assume that the land plot is in the shape of a polygon and coordinate axes have been setup such that the fence ABAB is parallel to xx -axis and the points where the watchtower can be set up are the integer points on the line. For example, in given figure 2, watchtower can be setup on any of five integer points on ABAB i.e. (4,8)(4,8) , (5,8)(5,8) , (6,8)(6,8) , (7,8)(7,8) or (8,8)(8,8) . You can assume that no three consecutive points are collinear and all the corner points other than AA and BB , lie towards same side of fence ABAB . The given polygon doesn't contain self-intersections.

输入格式

The first line of the test case will consist of the number of vertices nn ( 3<=n<=10003<=n<=1000 ).

Next nn lines will contain the coordinates of the vertices in the clockwise order of the polygon. On the ii -th line are integers xix_{i} and yiy_{i} ( 0<=xi,yi<=1060<=x_{i},y_{i}<=10^{6} ) separated by a space.

The endpoints of the fence ABAB are the first two points, (x1,y1)(x_{1},y_{1}) and (x2,y2)(x_{2},y_{2}) .

输出格式

Output consists of a single line containing the number of points where the watchtower can be set up.

输入输出样例

  • 输入#1

    5
    4 8
    8 8
    9 4
    4 0
    0 4
    

    输出#1

    5
    
  • 输入#2

    5
    4 8
    5 8
    5 4
    7 4
    2 2
    

    输出#2

    0
    

说明/提示

Figure 2 shows the first test case. All the points in the figure are watchable from any point on fence ABAB . Since, ABAB has 55 integer coordinates, so answer is 55 .

For case two, fence CDCD and DEDE are not completely visible, thus answer is 00 .

首页