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. 单字节编码&双字节编码

    单字节编码(WINDOWS-1252.ISO-8859-1.UTF-8) 双字节编码(UTF-16) Windows 记事本默认会将文件保存为单字节的 ANSI(ASCII).如果您选择 " ...

  2. python学习笔记5--加密模块hashlib

    import hashlib # md5 ybm_pwd='yuanbapqingsdfs234FF234HF@F' # m = hashlib.md5() # bytes_ybq = ybm_pwd ...

  3. Gnucash数据库结构

  4. AngularJs -- ngMessages(1.3+)

    ngMessages(1.3+) 表单和验证是AngularJS中复杂的组件之一.用AngularJS默认的方式来写,不是特别好,不简洁. 在AngualrJS1.3发布前,表单验证必须以这种方式编写 ...

  5. .gitignore 失效问题解决

    对于Git,已经跟踪的文件,再加入到.gitignore中,会使忽略失效.使用下面3个命令使它重新生效 git rm -r --cached . git add . git commit -m &qu ...

  6. 第5月第8天 jsonmodel

    1. @implementation JSONValueTransformer (CustomTransformer) //时间戳转NSDate - (NSDate *)NSDateFromNSStr ...

  7. python爬虫-图片批量下载

    # 爬起摄图网的图片批量下载# coding:utf-8 import requests from bs4 import BeautifulSoup from scipy.misc import im ...

  8. springMVC非注解常用的"处理器映射器"、"适配器"、"处理器"

    非注解处理器映射器1. org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping url 到bean name的映射2. or ...

  9. oracle 级联查询 根路径

    级联查询有很多教程示例,但是没有找到求特定子孙到根的路径的例子,折腾了一番总算想出方法了. 现假设我们拥有一个菜单表t_menu,其中只有三个字段:id.name和parent_id.它们是具有父子关 ...

  10. android休眠唤醒驱动流程分析【转】

    转自:http://blog.csdn.net/hanmengaidudu/article/details/11777501 标准linux休眠过程: l        power managemen ...