#284# div.2 C.Crazy Town

C. Crazy Town

Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi 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.

Input

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

The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 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 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 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

Output the answer to the problem.

Sample test(s)

Input

1 1-1 -120 1 01 0 0

Output

2

Input

1 1-1 -131 0 00 1 01 1 -3

Output

2

Note

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):

POINT:

  1.判断直线与线段是否相交即判断线段两端点是否在直线两侧;

  注意此题不能直接判断,因为乘积可能long long越界;

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<string>
 5 #include<algorithm>
 6 #include<map>
 7 using namespace std;
 8 const int maxn = 3010;
 9
10 struct Node
11 {
12     long long x, y;
13 }p1, p2;
14 int n;
15 int main()
16 {
17     scanf("%I64d%I64d%I64d%I64d", &p1.x, &p1.y, &p2.x, &p2.y);
18     scanf("%d", &n);
19     long long cnt = 0;
20     for(int i = 0; i < n; i++)
21     {
22         long long a, b, c;
23         scanf("%I64d%I64d%I64d", &a, &b, &c);
24         long long t1 = (a*p1.x + b*p1.y + c);
25         long long t2 = (a*p2.x + b*p2.y + c);
26         //  此处不能直接判断: long long 越界 !
27         if( (t1>0 && t2<0) || (t1<0 && t2>0) )  cnt++;
28     }
29     printf("%I64d\n", cnt);
30     return 0;
31 }
时间: 2024-10-10 02:20:54

#284# div.2 C.Crazy Town的相关文章

Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何

题面 题意:给你2个点A和B,和n条直线(ax+by+c=0),给n个a,b,c,求A到B至少跨过多少条直线 题解:对于每条直线,看2个点是否在他同侧,异侧答案就+1 1 #include<bits/stdc++.h> 2 using namespace std; 3 double x1,x2,y11,y2,a,b,c,t1,t2; 4 int n,ans; 5 int main() 6 { 7 cin>>x1>>y11; 8 cin>>x2>>

【codeforces #284(div 1)】ABC题解

A. Crazy Town time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix?+?biy?+?ci?=?0, where 

Codeforces Round #284 (Div. 1)

A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. 代码: 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<string> 5 #include<map> 6 #define N 100010 7 #def

Codeforces Round #284 (Div. 2) b

/**  * @brief Codeforces Round #284 (Div. 2) b  * @file b.cpp  * @author mianma  * @created 2014/12/26 11:51  * @edited  2014/12/18 11:51  * @type brute  * @note  */ #include <fstream> #include <iostream> #include <string> #include <c

[Codeforces Round #284 (Div. 1) B]Name That Tune(概率Dp)

Description It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the so

Codeforces Round #284 (Div. 2) C题(计算几何)解题报告

题目地址 简要题意: 给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A.B.C,这些直线作为街道,求从一点走到另一点需要跨越的街道数.(两点都不在街道上) 思路分析: 从一点到另一点必须要跨的街道等价于两点一点在这条直线一侧,另一条在另一侧.只需要将两点坐标带进去,一正一负即可.将这些直线依次检验,统计总和. 1 #include<stdio.h> 2 #include<bits/stdc++.h> 3 #include <iostream> 4 using

Codeforces Round #284 (Div. 2) A

解题思路:给出 n个电影的精彩时段(a[i],b[i]),和每次可以跳过的时间x,问要看完所有的精彩时刻,至少需要看多长时间的电影. 因为要时间最少,所有除了精彩时刻的电影则能跳过就跳过(用取余来算),不能跳过则加到耗费的总时间里面. 反思:WA两次是因为没有搞清楚物理上的时刻和时间的关系, -------------------------------------------------- 1    2     3     4      5      6       7       8 如果我

Codeforces Round #284 (Div. 2)

Problem C 题目大意:一个平面内有一些无限长的直线,把平面分成了若干块,从一块走一步可以走到与它有公共边的另一块,但是只有公共点不能一步走过去.给定两个在块内部的点,问从S点到T点最少走几步. 题目分析:由于每步只能跨越公共边,不能从两直线交点处跨越,所以一步只能越过 S 与 T 之间的一条直线,那么答案就是 S 与 T 之间有多少条直线(即 S 与 T 在这些直线的两侧).判断 S 与 T 在直线 l 两侧 :  l : ax + by + c = 0        (a*Sx + b

Codeforces Round #284 (Div.1) Solution

A 有意思,初看觉得怎么A还要求线交还这么麻烦.仔细一想.每次只能过一条线.如果有一条线在两点间,则必须过它们.在同侧的线不需要过.于是就简单了. B 时限好紧,我用了一个诡异的方法的时间复杂也是O(nT)却超了. C 奇数和偶数显然形成了二分图.对每一个素因子来一次最大流. D 首先注意到模LCM的60,噢.由于之前那个题,一下就想到分块大法好.什么嘛,明明就可以线段树呀.