C. Crazy Town
Crazy town was a plane on which there be n Infinite line roads. Each road was defined by the equation aix + biy + c i = 0, where ai and bi is not Both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each of such region a block. We define an intersection as the point where at least and 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 are nonzero (in particular, this m EANs that if the blocks is adjacent to one intersection, but has no shared nonzero boundary segment, then it is not all Owed to move from one to another one in one step).
Determine what's the minimum number of steps you has to perform to get to the block containing the university. It is guaranteed this neither your home nor the university is located on the road.
Input
The first line contains space-separated integers x1, y1 ( -6≤ x 1, y1≤106)-the coordinates of your home.
The second line contains and integers separated by a space x2, y2 ( -10 6≤ x 2, y2≤106)-the coordinates of the university you is studying at.
The third line contains an integerN(1≤N≤300)-the number of roads in the city. The following n lines contain 3 space-separated integers ( -6≤ ai, bi , ci ≤106; | a i| + | b i| > 0)-the coefficients of the line aix + b i y + c i = 0, defining the I-th Road. It is guaranteed, that no, and roads is the same. In addition, neither your home nor the university lie on the road (i.e. they does not belong to any one of the lines).
Output
Output the answer to the problem.
Sample Test (s) Input
1 1
-1-1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1-1
3
1 0 0
0 1 0
1 1-3
Output
2
Note
Pictures to the samples is presented below (A was the point representing the house; B is the point representing the university, different blocks be filled with different colors):
Point:
1. Determine whether the line and line segments intersect to determine whether the end point of the line is on both sides of the line;
Note that this problem cannot be directly judged, because the product may be a long long beyond the bounds;
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <string>5#include <algorithm>6#include <map>7 using namespacestd;8 Const intMAXN =3010;9 Ten structNode One { A Long Longx, y; - }p1, p2; - intN; the intMain () - { -scanf"%i64d%i64d%i64d%i64d", &p1.x, &p1.y, &p2.x, &p2.y); -scanf"%d", &n); + Long LongCNT =0; - for(inti =0; I < n; i++) + { A Long LongA, B, C; atscanf"%i64d%i64d%i64d", &a, &b, &c); - Long LongT1 = (a*p1.x + b*p1.y +c); - Long LongT2 = (a*p2.x + b*p2.y +c); - //cannot directly judge here: Long long out of bounds! - if((t1>0&& t2<0) || (t1<0&& t2>0)) cnt++; - } inprintf"%i64d\n", CNT); - return 0; to}
#284 # Div.2 C.crazy Town