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 -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 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越界;

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = ; struct Node
{
long long x, y;
}p1, p2;
int n;
int main()
{
scanf("%I64d%I64d%I64d%I64d", &p1.x, &p1.y, &p2.x, &p2.y);
scanf("%d", &n);
long long cnt = ;
for(int i = ; i < n; i++)
{
long long a, b, c;
scanf("%I64d%I64d%I64d", &a, &b, &c);
long long t1 = (a*p1.x + b*p1.y + c);
long long t2 = (a*p2.x + b*p2.y + c);
// 此处不能直接判断: long long 越界 !
if( (t1> && t2<) || (t1< && t2>) ) cnt++;
}
printf("%I64d\n", cnt);
return ;
}

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

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

    A. Crazy Town 题目连接: http://codeforces.com/contest/498/problem/A Description Crazy Town is a plane on ...

  2. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #284 (Div. 1)

    A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...

  4. Codeforces Round #284 (Div. 2)

    题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...

  5. C - Crazy Town

    Problem description Crazy Town is a plane on which there are n infinite line roads. Each road is def ...

  6. Codeforces 498A Crazy Town

    C. Crazy Town time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. A. Crazy Town

    Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation ...

  8. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

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

    题目地址 简要题意: 给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A.B.C,这些直线作为街道,求从一点走到另一点需要跨越的街道数.(两点都不在街道上) 思路分析: 从一点到另一点必须要跨 ...

随机推荐

  1. js基础第七天

    短信发送验证倒计时案例(常用) 关闭定时器clearInterval this 指向的是 事件的调用者 ,或者是函数的使用者. button 不可以用 disabled 不可用的意思 意思是变成灰色不 ...

  2. 问题与对策:CSS的margin塌陷(collapse)

    1: <!DOCTYPEHTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN"> 2: <html> 3: & ...

  3. 【Hadoop学习】CDH5.2安装部署

    [时间]2014年11月19日 [平台]Centos 6.5 [工具]scp [软件]jdk-7u67-linux-x64.rpm CDH5.2.0-hadoop2.5.0 [步骤] 1. 准备条件 ...

  4. 【bzoj2440】完全平方数

    题意: 求第n个不为完全平方数倍数的数 题解: 网上有人说答案不会超过2n (求证0 0?) 竟然不超过2n 那么很明显就是用二分做了 二分判定就是要求小于等于n的合法的数的个数 不难发现一个数若为完 ...

  5. IP查找工具——angry IP Scanner

    作用] 若树莓派没有屏幕可通过该工具查找树莓派的IP地址.例如下图的树莓派IP地址可能为192.168.1.107. 图1 IP scan查找树莓派IP地址

  6. 【C语言】-循环结构-for语句

    for语句: for (表达式1;表达式2;表达式3) { 循环语句 } 表达式1 给循环变量赋初值 表达式2 为循环条件 表达式3 用来修改循环变量的值,称为循环步长. for语句的执行流程: 例: ...

  7. Introduction to DTD

    A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines th ...

  8. [OC Foundation框架 - 5] NSString的常用方法

             NSString *s1 = ";   1.比较 使用 == 号比较的是字符串地址 NSString *s4 = @"abcdefg"; NSStrin ...

  9. [置顶] [BZOJ]2127: happiness 最小割

    happiness: Description 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科与理科有着自己 ...

  10. mysql事物

    一. 什么是事务 事务就是一段sql 语句的批处理,但是这个批处理是一个atom(原子) ,不可分割,要么都执行,要么回滚(rollback)都不执行. 二.为什么出现这种技术 为什么要使用事务这个技 ...