#284 div.2 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.
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 the answer to the problem.
1 1
-1 -1
2
0 1 0
1 0 0
2
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
2
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越界;
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = ; struct Node
{
long long x, y;
}p1, p2;
int n;
int main()
{
scanf("%I64d%I64d%I64d%I64d", &p1.x, &p1.y, &p2.x, &p2.y);
scanf("%d", &n);
long long cnt = ;
for(int i = ; i < n; i++)
{
long long a, b, c;
scanf("%I64d%I64d%I64d", &a, &b, &c);
long long t1 = (a*p1.x + b*p1.y + c);
long long t2 = (a*p2.x + b*p2.y + c);
// 此处不能直接判断: long long 越界 !
if( (t1> && t2<) || (t1< && t2>) ) cnt++;
}
printf("%I64d\n", cnt);
return ;
}
#284 div.2 C.Crazy Town的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #284 (Div. 1)
A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...
- Codeforces Round #284 (Div. 2)
题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...
- C - Crazy Town
Problem description Crazy Town is a plane on which there are n infinite line roads. Each road is def ...
- Codeforces 498A Crazy Town
C. Crazy Town time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- A. Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation ...
- Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word
Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...
- Codeforces Round #284 (Div. 2) C题(计算几何)解题报告
题目地址 简要题意: 给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A.B.C,这些直线作为街道,求从一点走到另一点需要跨越的街道数.(两点都不在街道上) 思路分析: 从一点到另一点必须要跨 ...
随机推荐
- 线性存储结构-ArrayList、Vector
ArrayList:采用数组的内部构建形式,也就是顺序存储模式.当新增一个对象时,如果当前长度超过预设,会使用System.arraycopy(定义一个更长的数组进行复制处理),这个时候开销比较大. ...
- 全文检索- Oracle/MySql/达梦
简单使用语法: MySql: ALTER TABLE dataset_ods ENGINE = MyISAM; //5.6后的InnoDB支持全文索引 ALTER TABLE dataset_ods ...
- TCP服务端和客户端的框架
提供一个框架服务器端: 创建一个Socket sFd=socket(AF_INET,SOCK_STREAM,0) 把Socket和本机的IP,TCP口绑定 bind(sFd,(structsockad ...
- Redhat Enterprise Linux 6.4图形界面的中文问题
一.界面中文,但Windows中的中文文件名上传到linux后乱码. .bashrc文件: export LANG=zh_CN.UTF-8 /etc/sysconfig/i18n文件: LANG=&q ...
- [转载]mac下homebrew的使用
该文转自:https://www.zybuluo.com/phper/note/87055 mac系统也是基于unix的系统,所以也继承类很多unix的特性,包括软件的编译,安装等.ubuntu下有快 ...
- 宿舍局域网与Internet连接
写在前面的话 一般情况下,大多数组建了校园网的学校都为学生宿舍提供了连接Internet接口,所以只需要通过网线将宿舍网的集线器与校园网提供的接口进行连接即可接入Internet.宿舍网接入Inter ...
- Java网络编程(TCP客户端)
TCP传输:两个端点建立连接后会有一个传输数据的通道,这个通道就称为流,而且是建立在网络基础上的流,之为socket流,该流中既可以读取也可以写入. TCP的两个端点:一个客户端:ServerSock ...
- 转载C#函数式程序设计初探——基础理论篇
转载网址:http://www.cnblogs.com/Hlia/archive/2013/04/20/3029701.html 个人认为,C#语言的某些设计并不非常适合函数式开发,比如它的类型推断并 ...
- android四大功能组件概要总结
1.activity 某一个activity对应于app中的一个具体的页面.而intent是具些activity都具有的同类型操作的抽象,比如Main View Edit PICK 已及所对应的数据 ...
- mysql之一
MySQL or MariaDB 简介 DBMS:数据库管理系统 RDBMS:关系型数据库管理系统 总之:他们都是一个数据管理程序:大多都是CS架构,都有专门的通信协议进行数据交换 关系模型: ...