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 ;
}
}

最新文章

  1. 洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game
  2. 《JavaScript高级程序设计》心得笔记-----第二篇章
  3. JPA与ORM以及Hibernate
  4. TCP/IP笔记 应用层(1)——DNS
  5. 「python」: arp脚本的两种方法
  6. oracle-创建表空间报错 提示ora-01119 ora-27040:无法创建文件
  7. Git版本控制:Git冲突解决 相关错误总结
  8. go语言打造p2p网络
  9. TableLayout中collapseColumns,stretchColumns的介绍
  10. String 简介
  11. Robust Mesh Watermarking
  12. jackson springboot null节点忽略配置
  13. NAT 穿透
  14. Windows Server 2012/win8 iis8 上安装 asp.net 4.5 当时用了mvc5 .net framework 4.5 所以得装下
  15. Comet事件分析
  16. 实际用户ID,有效用户ID,保存的设置用户ID
  17. 获取表单select域的选择部分的文本
  18. PHP入门笔记--基础语法一
  19. 【Python】python中的__dict__,__getattr__,__setattr__
  20. 如何成为一名:黑客/Programmer/Python高手

热门文章

  1. ActiveMQ的简单使用
  2. Springboot2.x整合SpringSecurity
  3. Python Web开发:Django+BootStrap实现简单的博客项目
  4. 2018-2-13-C#-Find-vs-FirstOrDefault
  5. 2018-2-13-C#-搜索算法
  6. 312-金胜维 P系列2.5寸 480G SATA3 SSD固态硬盘
  7. Tomcat架构与原理
  8. OpenStack虚拟机网络问题
  9. phpstorm 开发php入门
  10. python socket基本连接功能实现