A. Crazy Town

题目连接:

http://codeforces.com/contest/498/problem/A

Description

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 bi are 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 Input

1 1

-1 -1

2

0 1 0

1 0 0

Sample Output

2

Hint

题意

给你两个点A,B

然后给你n条直线,这n条直线会把平面切成几块,然后问你从A走到B至少跨过多少条直线。

题解:

对于每一条直线,判断这两个点是否在同侧就好了。

但是乘法会爆long long。。。

所以就直接判断符号吧

代码

#include<bits/stdc++.h>
using namespace std; int main()
{
long long x1,x2,y1,y2;
cin>>x1>>y1;
cin>>x2>>y2;
int n;
scanf("%d",&n);
int ans = 0;
for(int i=0;i<n;i++)
{
long long a,b,c;
cin>>a>>b>>c;
long long tmp1 = a*x1+b*y1+c;
long long tmp2 = a*x2+b*y2+c;
if(tmp1>0 != tmp2>0)
ans++;
}
cout<<ans<<endl;
}

Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何的更多相关文章

  1. Codeforces Round #284 (Div. 2) C题(计算几何)解题报告

    题目地址 简要题意: 给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A.B.C,这些直线作为街道,求从一点走到另一点需要跨越的街道数.(两点都不在街道上) 思路分析: 从一点到另一点必须要跨 ...

  2. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

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

  4. Codeforces Round #284 (Div. 2)

    题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...

  5. Codeforces Round #284 (Div. 1)

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

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

  7. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配

    题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...

  8. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配

    因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #de ...

  9. Codeforces Round #284 (Div. 2) D. Name That Tune [概率dp]

    D. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. bzoj千题计划273:bzoj4710: [Jsoi2011]分特产

    http://www.lydsy.com/JudgeOnline/problem.php?id=4710 答案=总方案数-不合法方案数 f[i][j] 前i种特产分给j个人(可能有人没有分到特产)的总 ...

  2. ASP.net学习总结

    学习ASP.net又一次接触了B/S开发.下面先通过一张图对ASP.net有一个宏观结构的总结.之后将详细介绍ASP.net中的六大对象. 1.Request从客户端得到数据,包括基于表单的数据和通过 ...

  3. 【问题收集·知识储备】Xcode只能选择My Mac,不能选择模拟器如何解决?

      网友问题:请问打开一个应用,只能选择My Mac,不能选择模拟器如何解决? 答案:             下面将问答过程记录如下:     CHENYILONG Blog 请问打开一个应用,只能 ...

  4. Python 入门基础1 --语言介绍

    本节目录: 一.编程语言介绍 二.python解释器介绍 三.安装python解释器 四.运行python程序的两种方式 五.变量 六.后期补充内容 一.编程语言介绍 1.机器语言: 直接用二进制编程 ...

  5. nodejs 配置服务自启动

    1安装包 输入以下命令,安装需要的包 npm install node-windows -g 2编写自启动js 在目标server.js目录下新建auto_start_nodejs.js文件,将以下j ...

  6. 局域网搭建https局域网

    局域网搭建https局域网 1.使用tomcat作为服务器搭建局域网访问https 需要使用java jdk\bin下的keytool.exe来创建证书 使用命令:keytool -genkenpai ...

  7. Database Course Summary 001

    0x01. 基本概念 SQL:Structured English Query Language 1. 数据 Data 数据(Data):描述事物的符号记录:数据内容是事物特性的反应或描述:数据是符号 ...

  8. Intellij IDEA15: 带着参数 运行

    package main.scala /** * Created by silentwolf on 2016/5/24. */ object FileIO { def main(args: Array ...

  9. Nginx+redis的Asp.net

    基于Nginx+redis的Asp.net站点搭建   剧情介绍 在传统的信息系统(比如小规模的ERP\MES系统),往往只是进行简单的应用服务器和数据库服务器的分布式部署,以此来提高应用系统的负载能 ...

  10. getImplementationVersion-获取版本号

    在工作中会遇到这个方法的使用,就记录一下. 一:getImplementationVersion 1.  方法 java.lang.Package.getImplementationVersion() ...