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. Vue PC端图片预览插件

    *手上的项目刚刚搞完了,记录一下项目中遇到的问题,留做笔记: 需求: 在项目中,需要展示用户上传的一些图片,我从后台接口拿到图片url后放在页面上展示,因为被图片我设置了宽度限制(150px),所以图 ...

  2. JSON —— 数据结构

    1.什么是 JSON JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写 JSON 采用完全独立于语言的文本格式,但是也使用了类似于 C ...

  3. Android线程间通信的几种实现方式

    1. 通过Handler机制: private void one() { handler=new Handler(){ @Override public void handleMessage(Mess ...

  4. 使用logstash同步MongoDB数据到es

    input{ mongodb{ codec => "json" uri => 'mongodb://127.0.0.1:27017/kuaibao' placehold ...

  5. linux性能分析工具Cpu

  6. k8s阅读笔记1-云原生

    前言 阅读书籍地址https://rootsongjc.gitbooks.io/kubernetes-handbook/content/cloud-native/cloud-native-defini ...

  7. 【Leetcode周赛】从contest-71开始。(一般是10个contest写一篇文章)

    Contest 71 () Contest 72 () Contest 73 (2019年1月30日模拟) 链接:https://leetcode.com/contest/weekly-contest ...

  8. ltp-ddt genload

    under folder tools\genload   genload.c             "`%s' imposes certain types of compute stres ...

  9. wraps的补充

    # import time# def index(name):# '''index函数'''# time.sleep(1)# print('Welcome %s to China'%name)# re ...

  10. ROS环境下使用Wireshark抓包(网桥)

    在ROS的管理工具>数据包探测设置里>常规接口选为LAN,数据流>数据流启用>服务器:Wireshark电脑的IP,筛选> IP选要抓包的IP地址 然后在Wireshar ...