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

这题想通后很简单,就是看A,B两点间的直线有几条,用零点法看是否一正一负就行。注意一点要分两种情况讨论,不然会爆__int64.

#include<stdio.h>

#include<string.h>

int main()

{
__int64 x1,y1,x2,y2,i,j,a,b,c;
int n,sum;
while(scanf("%I64d%I64d",&x1,&y1)!=EOF)
{
scanf("%I64d%I64d",&x2,&y2);
scanf("%d",&n);
sum=0;
for(i=1;i<=n;i++){
scanf("%I64d%I64d%I64d",&a,&b,&c);
if(a*x1+b*y1+c>0 && a*x2+b*y2+c<0){
sum++;continue;
}
if(a*x1+b*y1+c<0 && a*x2+b*y2+c>0){
sum++;continue;
}
}
printf("%d\n",sum);
}

}

A. Crazy Town的更多相关文章

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

  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. C - Crazy Town

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

  4. Codeforces 498A Crazy Town

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

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

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

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

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

  7. 【codeforces 499C】Crazy Town

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

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

  9. Codeforces Round #284 (Div. 1)

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

随机推荐

  1. LeetCode234 回文链表

    请判断一个链表是否为回文链表. 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶:你能否用 O(n) 时间复杂 ...

  2. 没搞清楚网络I/O模型?那怎么入门Netty

    微信搜索[阿丸笔记],关注Java/MySQL/中间件各系列原创实战笔记,干货满满. 本文是Netty系列笔记第二篇 Netty是网络应用框架,所以从最本质的角度来看,是对网络I/O模型的封装使用. ...

  3. C语言逗号运算符(C语言学习笔记)

    什么是逗号运算符 逗号运算符 逗号运算符是指在C语言中,多个表达式可以用逗号分开,其中用逗号分开的表达式的值分别结算,但整个表达式的值是最后一个表达式的值. 用法 多个变量赋值 原因:"=& ...

  4. EF Core 6.0的新计划

    今天,我们很兴奋地与你分享Entity Framework Core 6.0的计划. 这个计划汇集了许多人的意见,并概述了我们打算在哪里以及如何优化实体框架(EF Core) 6.0版本.这个计划并不 ...

  5. 1V转3V的低功耗升压芯片

       由于1V的电压很低,如果需要1V转3V的芯片,也是能找到的,一般要输入电压要选择余量,选择比1V更低的启动电压的1V转3V升压芯片.PW5100干电池升压IC就具有1V转3V,稳压输出3.3V的 ...

  6. 三节锂电池充电管理芯片,IC电路图如何设计

    关于三节锂电池供电的产品,在三节锂电池上,需要三个电路系统: 1,三节锂电池保护电路, 2,三节锂电池充电电路, 3,三节锂电池输出电路. 1.三节锂电池保护电路,芯片电路图 控制三节锂电池池的充电电 ...

  7. 2020年12月18号--21号 人工智能(深度学习DeepLearning)python、TensorFlow技术实战

    深度学习DeepLearning(Python)实战培训班 时间地点: 2020 年 12 月 18 日-2020 年 12 月 21日 (第一天报到 授课三天:提前环境部署 电脑测试) 一.培训方式 ...

  8. JavaScript中函数的调用!

    JavaScript中函数的调用! 1 普通函数 // 1 普通函数 function fn() { console.log(123); } // 函数名 + 一个小括号! 或者 函数名.call() ...

  9. 浅谈linux IO csy 360技术 2021-01-18

    浅谈linux IO csy 360技术 2021-01-18

  10. (Oracle)数据库用户的密码过期时间如何修改为永不过期

    Oracle的密码过期规则是用Profile来管理的,系统默认只有一个Profile(DEFAULT),该profile的密码过期规则为180天.那么如何修改Oracle数据库用户的密码过期时间为永不 ...