C. 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 ai and biare 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):

不难发现中间有多少条线在两点之间,就要走过多少个区域

输入给出了直线的一般式,那么只要把两个点代进直线方程,就可以判断它在左边还是右边。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
#define X first
#define Y second
const int N = ; pii e,s;
bool check( LL a , LL b , LL c ) {
LL res1 = s.X * a + s.Y * b + c ;
LL res2 = e.X * a + e.Y * b + c ;
if( res1 > && res2 < ) return true ;
if( res2 > && res1 < ) return true ;
return false ;
} int main(){
// freopen("in.txt","r",stdin);
LL n , m , res , a , b , c ;
while( cin >> s.X >> s.Y >> e.X >> e.Y ) {
res = ;
cin >> n ;
for( int i = ; i < n ; ++i ){
cin >> a >> b >> c ;
if( check( a , b ,c ) ) res++;
}
cout << res << endl ;
}
}

Codeforces 498A Crazy Town的更多相关文章

  1. Codeforces 499C:Crazy Town(计算几何)

    题目链接 给出点A(x1,y1),B(x2,y2),和n条直线(ai,bi,ci,aix + biy + ci = 0),求A到B穿过多少条直线 枚举每条直线判断A.B是否在该直线两侧即可 #incl ...

  2. 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 ...

  3. #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 ...

  4. C - Crazy Town

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

  5. A. Crazy Town

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

  6. 【codeforces 499C】Crazy Town

    [题目链接]:http://codeforces.com/problemset/problem/499/C [题意] 一个平面,被n条直线分成若干个块; 你在其中的某一块,然后你想要要到的终点在另外一 ...

  7. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. CodeForces 716A Crazy Computer

    题目链接:http://codeforces.com/problemset/problem/716/A 题目大意: 输入 n c, 第二行 n 个整数,c表示时间间隔 秒. 每个整数代表是第几秒.如果 ...

  9. Codeforces_499C:Crazy Town(计算几何)

    题目链接 给出点A(x1,y1),B(x2,y2),和n条直线(ai,bi,ci,aix + biy + ci = 0),求A到B穿过多少条直线 枚举每条直线判断A.B是否在该直线两侧即可 #incl ...

随机推荐

  1. 机器学习-线性回归补充-R^

    线性回归算法在选自变量会遇到两个问题:一是去掉多重共线性干扰,二是选择最优自变量组合. 线性回归步骤 1.选择自变量 注意点 去掉多重共线性干扰,选择最优自变量组合.这里需要理解决定系数:R^.它是理 ...

  2. 04.Linux-CentOS系统SSH连接问题

    问题:SSH远程连接时报错 Socket error Event: 32 Error: 10053.Connection closing...Socket close.Connection close ...

  3. 03.Linux-CentOS系统user用户改密码问题

    问题:[user@localhost ~]$ passwdChanging password for user user.Changing password for user.(current) UN ...

  4. json字符串处理—Json&C#

    C# 转自:https://blog.csdn.net/sajiazaici/article/details/77647625# 本文是全网第二简单的方法,因为我女票也发了一篇博客说是全网最简单的方法 ...

  5. 莫比乌斯反演/线性筛/积性函数/杜教筛/min25筛 学习笔记

    最近重新系统地学了下这几个知识点,以前没发现他们的联系,这次总结一下. 莫比乌斯反演入门:https://blog.csdn.net/litble/article/details/72804050 线 ...

  6. html5 lineTo的使用例子

    demo.js function draw(id) { var CANVAS=document.getElementById(id); var context=CANVAS.getContext('2 ...

  7. Spring Transaction Propagation

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11530611.html REQUIRED behavior Spring REQUIRED behav ...

  8. 解决swagger跨项目或跨程序集注释不显示问题

    背景 我们在使用Swagger生成.NET Core Web Api 项目接口文档时候,发现接口的入参和出参的注释是看不见的,如下: 但是我想要结果是这样: 原因分析以及方案 为什么没有显示注释呢,注 ...

  9. 0-3为变长序列建模modeling variable length sequences

    在本节中,我们会讨论序列的长度是变化的,也是一个变量 we would like the length of sequence,n,to alse be a random variable 一个简单的 ...

  10. 英语单词SYNOPSIS

    SYNOPSIS 来源——man帮助内容 BASH() General Commands Manual BASH() NAME bash - GNU Bourne-Again SHell SYNOPS ...