302575: CF498A. Crazy Town

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Crazy Town

题意翻译

求与线段AB(你家与学校连线)相交的直线数量 输入格式: 第一行表示A(你家)的坐标x1​,y1​ 第二行表示B(学校)的坐标x2​,y2​ 第三行是一个数字n,表示直线数量 接下来n行表示第i条直线axi​+byi​+c=0中的a,b,c 输出格式: 一个数字,表示与线段AB相交的直线数量 数据范围: 1≤n≤300; 106≤ai​,bi​,ci​≤106;∣ai​∣+∣bi​∣>0;

题目描述

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.

输入输出格式

输入格式


The first line contains two space-separated integers $ x_{1} $ , $ y_{1} $ ( $ -10^{6}<=x_{1},y_{1}<=10^{6} $ ) — the coordinates of your home. The second line contains two integers separated by a space $ x_{2} $ , $ y_{2} $ ( $ -10^{6}<=x_{2},y_{2}<=10^{6} $ ) — 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 ( $ -10^{6}<=a_{i},b_{i},c_{i}<=10^{6} $ ; $ |a_{i}|+|b_{i}|&gt;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).

输出格式


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): ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF498A/8c66a00538adfef29ce1baa3198c138a47ea6e13.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF498A/29b77b7e33fa199e4ec2e237dc82e647e7f04f88.png)

Input

题意翻译

求与线段AB(你家与学校连线)相交的直线数量 输入格式: 第一行表示A(你家)的坐标x1​,y1​ 第二行表示B(学校)的坐标x2​,y2​ 第三行是一个数字n,表示直线数量 接下来n行表示第i条直线axi​+byi​+c=0中的a,b,c 输出格式: 一个数字,表示与线段AB相交的直线数量 数据范围: 1≤n≤300; 106≤ai​,bi​,ci​≤106;∣ai​∣+∣bi​∣>0;

加入题单

算法标签: