CF67E.Save the City!

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

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 AB 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 X, Y, C and A are visible from point B but the points E and D 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 AB is parallel to x-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 AB i.e. (4, 8), (5, 8), (6, 8), (7, 8) or (8, 8). You can assume that no three consecutive points are collinear and all the corner points other than A and B, lie towards same side of fence AB. The given polygon doesn't contain self-intersections.

在阿拉姆-阿拉镇(意为“大地之光”),过去从未发生过犯罪,也不存在罪犯;但随着时间推移,罪恶逐渐渗入原本正直之人的心中。为解决这一问题,一些长者发现:只要将已被腐蚀的人群与未被腐蚀的人群隔离开来,犯罪行为便可得以遏制。因此,他们正计划修建一座围栏式监禁区,用以关押那些已被腐蚀者。为确保罪犯无法逃脱该区域,需设立一座瞭望塔,以便对其进行监视。

由于阿拉姆-阿拉镇居民并不富裕,他们找到一位来自富庶城镇的商人,该商人同意出售一块已建有直线围栏 ABAB 的土地;围栏 ABAB 上已标出若干可设置瞭望塔的点。你的任务是帮助他们确定:围栏 ABAB 上共有多少个点可设置瞭望塔,使得所有罪犯均能被该塔监视到(仅允许设置一座瞭望塔)。若从瞭望塔到某罪犯的视线在二者之间不与地块边界相交,则该罪犯可视(即可被监视)。如图1所示,从点 BB 可见的点包括 XX、YY、CC 和 AA,而点 EE 与 DD 不可见。

图1

图2

假设该地块呈多边形形状,且坐标系已设定妥当,使得围栏 ABAB 平行于 xx 轴;而可供设置瞭望塔的点即为该直线上所有整数坐标点。例如,在图2中,瞭望塔可设于围栏 ABAB 上任意一个整数点,即 (4, 8)(4, 8)、(5, 8)(5, 8)、(6, 8)(6, 8)、(7, 8)(7, 8) 或 (8, 8)(8, 8) 这五个点之一。你可以假设:不存在三个连续顶点共线的情形;除端点 AA 与 BB 外,其余所有顶点均位于围栏 ABAB 的同一侧;且所给多边形无自相交。

输入格式

The first line of the test case will consist of the number of vertices n (3 ≤ n ≤ 1000).

Next n lines will contain the coordinates of the vertices in the clockwise order of the polygon. On the i-th line are integers x__i and y__i (0 ≤ x__i, y__i ≤ 106) separated by a space.

The endpoints of the fence AB are the first two points, (_x_1, _y_1) and (_x_2, _y_2).

测试用例的第一行包含顶点数 nn(3 ≤ n ≤ 10003 \leq n \leq 1000)。

接下来的 nn 行将按顺时针顺序给出多边形各顶点的坐标。第 ii 行包含两个整数 xix_i 和 yiy_i(0 ≤ xi, yi ≤ 1060 \leq x_i,\,y_i \leq 10^6),以空格分隔。

围栏 ABAB 的两个端点为前两个点,即 (x1, y1)(x_1,\,y_1) 和 (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 AB. Since, AB has 5 integer coordinates, so answer is 5.

For case two, fence CD and DE are not completely visible, thus answer is 0.

图 2 展示了第一个测试用例。图中所有点均可从围栏 ABAB 上的任意一点观测到。由于 ABAB 上有 5 个整数坐标点,因此答案为 5。

对于第二个测试用例,围栏 CDCD 和 DEDE 并非完全可见,因此答案为 0。

输入解题思路,AI测评打分。不知道怎么写?

首页