CF498A.Crazy Town

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation a__i__x + b__i__y + c__i = 0, where a__i and b__i are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.

Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).

Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.

疯狂镇是一个平面上有 nn 条无限长直线道路的区域。每条道路由方程 aix+biy+ci=0a_i x + b_i y + c_i = 0 定义,其中 aia_i 和 bib_i 不同时为零。这些道路将平面划分为若干连通区域(可能包含无限延伸的区域)。我们将每个这样的区域称为一个“街区”(block)。我们把至少两条不同道路相交的点定义为一个“交叉口”(intersection)。

你的家位于某个街区中。今天你需要前往大学,而大学也位于某个街区中。每一步,你可以从一个街区移动到另一个街区,当且仅当这两个街区具有长度非零的公共边界(特别地,这意味着:即使两个街区都邻接同一个交叉口,但若它们之间没有长度非零的公共边界线段,则不允许在一步内从一个街区移动到另一个街区)。

请确定:要到达大学所在的街区,你最少需要多少步?题目保证:你的家和大学均不位于任何一条道路上。

输入格式

The first line contains two space-separated integers _x_1, _y_1 ( - 106 ≤ _x_1, _y_1 ≤ 106) — the coordinates of your home.

The second line contains two integers separated by a space _x_2, _y_2 ( - 106 ≤ _x_2, _y_2 ≤ 106) — the coordinates of the university you are studying at.

The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ a__i, b__i, c__i ≤ 106; |a__i| + |b__i| > 0) — the coefficients of the line a__i__x + b__i__y + c__i = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).

第一行包含两个以空格分隔的整数 x1x_1, y1y_1(−106≤x1,y1≤106-10^6 \le x_1, y_1 \le 10^6)——表示你家的坐标。

第二行包含两个以空格分隔的整数 x2x_2, y2y_2(−106≤x2,y2≤106-10^6 \le x_2, y_2 \le 10^6)——表示你所在大学的坐标。

第三行包含一个整数 nn(1≤n≤3001 \le n \le 300)——表示城市中道路的数量。接下来的 nn 行每行包含三个以空格分隔的整数(−106≤ai,bi,ci≤106-10^6 \le a_i, b_i, c_i \le 10^6;∣ai∣+∣bi∣>0|a_i| + |b_i| > 0)——表示第 ii 条道路所对应的直线方程 aix+biy+ci=0a_i x + b_i y + c_i = 0 的系数。保证任意两条道路不重合。此外,你的家和大学均不在任何一条道路上(即它们均不属于任意一条直线)。

输出格式

Output the answer to the problem.

输出问题的答案。

输入输出样例

  • 输入#1

    1 1
    -1 -1
    2
    0 1 0
    1 0 0

    输出#1

    2
  • 输入#2

    1 1
    -1 -1
    3
    1 0 0
    0 1 0
    1 1 -3

    输出#2

    2

说明/提示

Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):

下图展示了样例(A 点表示住宅;B 点表示大学,不同的区域用不同颜色填充):

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

首页