C. Crazy Town
 

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 test(s)
Input
  1. 1 1
    -1 -1
    2
    0 1 0
    1 0 0
Output
  1. 2
Input
  1. 1 1
    -1 -1
    3
    1 0 0
    0 1 0
    1 1 -3
Output
  1. 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):

POINT:

  1.判断直线与线段是否相交即判断线段两端点是否在直线两侧;

  注意此题不能直接判断,因为乘积可能long long越界;

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<string>
  5. #include<algorithm>
  6. #include<map>
  7. using namespace std;
  8. const int maxn = ;
  9.  
  10. struct Node
  11. {
  12. long long x, y;
  13. }p1, p2;
  14. int n;
  15. int main()
  16. {
  17. scanf("%I64d%I64d%I64d%I64d", &p1.x, &p1.y, &p2.x, &p2.y);
  18. scanf("%d", &n);
  19. long long cnt = ;
  20. for(int i = ; i < n; i++)
  21. {
  22. long long a, b, c;
  23. scanf("%I64d%I64d%I64d", &a, &b, &c);
  24. long long t1 = (a*p1.x + b*p1.y + c);
  25. long long t2 = (a*p2.x + b*p2.y + c);
  26. // 此处不能直接判断: long long 越界 !
  27. if( (t1> && t2<) || (t1< && t2>) ) cnt++;
  28. }
  29. printf("%I64d\n", cnt);
  30. return ;
  31. }

#284 div.2 C.Crazy Town的更多相关文章

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

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

  3. Codeforces Round #284 (Div. 1)

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

  4. Codeforces Round #284 (Div. 2)

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

  5. C - Crazy Town

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

  6. Codeforces 498A Crazy Town

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

  7. A. Crazy Town

    Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation ...

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

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

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

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

随机推荐

  1. ExtJS 5.0版本问题+Sencha cmd

    ExtJS 5.0版本官方网站给的图表例子,以散点图作说明: Ext.create('Ext.Container', { //renderTo: Ext.getBody(), width: 600, ...

  2. MATLAB和c#混合编程实现心电图显示软件

    [在此处输入文章标题] 由于MATLAB自带的GUI平台设计的界面不是很美观而且设计过程并不是很方便,我们选择了用c#来做软件界面的实现.我们用MATLAB做信号处理封装成函数,把函数编译成dll格式 ...

  3. Java之文件的随机访问和读写RandomAccessFile

    package FileDemo; import java.io.IOException; import java.io.RandomAccessFile; public class RandomAc ...

  4. 关于七牛云存储,HTTPS资源上传不成功问题

    关于七牛云存储,HTTPS资源上传不成功问题 官方给出了一个解决方案,亲测可用.特此记录一下. 找到QNConfiguration.m文件.然后重写两个方法,直接上代码. + (instancetyp ...

  5. DOS/Windows下黑客攻防(一)——神秘黑客大曝光

    一.认识神秘的黑客 谈到网络安全,人们不自觉间就会联想到黑客,人们往往会将他们同破坏网络安全.盗取用户账号.偷窃个人私密信息联系起来.其实黑客也有好坏之分,他们并不全是网络上的捣乱分子,其中也有一部分 ...

  6. 【Stage3D学习笔记续】山寨Starling(三):Starling核心渲染流程

    这篇文章我们剔除Starling的Touch事件体系和动画体系,专门来看看Starling中的渲染流程实现,以及其搭建的显示列表结构. 由于Starling是模仿Flash的原生显示列表,所以我们可以 ...

  7. android飞机游戏敌机移动路径

    基础android的飞机类游戏,与前人一样,由surfaceView绘制游戏画面,另起线程控制绘制时间间隔达到动态效果.这里附上最近自己写的敌机自动飞行路径代码.请大家给点意见. 在敌机管理模块,加入 ...

  8. cocos2d-x UserDefault

    转自:http://blog.csdn.net/yanghuiliu/article/details/6912612 正在做项目中有很多游戏数据要保存,常见的玩家数据这些比较简单的可以用CCUserD ...

  9. iOS开发——数据持久化Swift篇&通用文件存储

    通用文件存储 import UIKit class ViewController: UIViewController { @IBOutlet weak var textField: UITextFie ...

  10. javascript中false值及其常见比较运算

    1. ture或者false的值 if判断中会被隐式转换成false的boolean类型的值有 false, 0, undefined , null , '', NaN(not a number) 除 ...