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. Dubbo+Zookeeper(二)Dubbo架构

    上次更新博客已经是一年前,这一年发生了很多事,并不顺利,甚至有些痛苦,不过不管怎样,不要停止学习,只有学习才能让你变强,应对更多不安定. 一.RPC概念 Dubbo服务是一个RPC框架,那我们首先就要 ...

  2. QPainter 绘制图像接口

    阅读本文大概需要 3 分钟 我们在开发软件的过程中,绘制图像功能必不可少,使用 Qt 绘制图像时非常简单,只需要传递几个参数就可以实现功能,在 Qt 中绘制图像的 api有好几个 void drawI ...

  3. 【Linux】shell脚本实现多并发

    情景 shell脚本的执行效率虽高,但当任务量巨大时仍然需要较长的时间,尤其是需要执行一大批的命令时.因为默认情况下,shell脚本中的命令是串行执行的.如果这些命令相互之间是独立的,则可以使用&qu ...

  4. 史上最全postgreSQL体系结构(转)

    原文链接:https://cloud.tencent.com/developer/article/1469101 墨墨导读:本文主要从日志文件.参数文件.控制文件.数据文件.redo日志(WAL).后 ...

  5. the7主题 一个强大的wordpress 主题 html5拖拽式建站系统

    演示地址 http://the7.net The7汉化主题.可视化编辑器和终极交互式模块插件完全无缝集成,可以让你完全自由的布局或者创意实现你的网站,真正的建站仿站利器. The7的750+个主题设置 ...

  6. 优化太多的if-else

    来源java小当家 第1种方法:提前return,减少else判断 1 // 1.优化前 2 private int handlerPre1(boolean flag) { 3 if(flag){ 4 ...

  7. JWT令牌简介及demo

    一.访问令牌的类型 二.JWT令牌 1.什么是JWT令牌 ​ JWT是JSON Web Token的缩写,即JSON Web令牌,是一种自包含令牌. JWT的使用场景: 一种情况是webapi,类似之 ...

  8. Maven + springboot + mybatis 构建多模块工程

    废话不说先上最终效果:创建一个空项目,再创建一个父项目用来管理各模块并维护各模块关系,简要说明如下: parent模块:主要用来管理以下各模块,和各模块涉及的jar包版本和boot项目入口级的的依赖管 ...

  9. 计算机网络安全 —— 非对称加密算法 RSA 和数字签名(二)

    一.非对称加密算法基本概念 在对称密钥系统中,两个参与者要共享同一个秘密密钥.但怎样才能做到这一点呢?一种是事先约定,另一种是用信使来传送.在高度自动化的大型计算机网络中,用信使来传送密钥显然是不合适 ...

  10. jQuery json遍历渲染到页面并且拼接html

    jQuery 处理 json遍历在页面中显示,并且拼接html. 1 <title>json多维数组遍历渲染</title> 2 3 <body> 4 <di ...