Codeforces 498A Crazy Town
1 second
256 megabytes
standard input
standard output
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.
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):


不难发现中间有多少条线在两点之间,就要走过多少个区域
输入给出了直线的一般式,那么只要把两个点代进直线方程,就可以判断它在左边还是右边。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
#define X first
#define Y second
const int N = ; pii e,s;
bool check( LL a , LL b , LL c ) {
LL res1 = s.X * a + s.Y * b + c ;
LL res2 = e.X * a + e.Y * b + c ;
if( res1 > && res2 < ) return true ;
if( res2 > && res1 < ) return true ;
return false ;
} int main(){
// freopen("in.txt","r",stdin);
LL n , m , res , a , b , c ;
while( cin >> s.X >> s.Y >> e.X >> e.Y ) {
res = ;
cin >> n ;
for( int i = ; i < n ; ++i ){
cin >> a >> b >> c ;
if( check( a , b ,c ) ) res++;
}
cout << res << endl ;
}
}
Codeforces 498A Crazy Town的更多相关文章
- Codeforces 499C:Crazy Town(计算几何)
题目链接 给出点A(x1,y1),B(x2,y2),和n条直线(ai,bi,ci,aix + biy + ci = 0),求A到B穿过多少条直线 枚举每条直线判断A.B是否在该直线两侧即可 #incl ...
- 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 ...
- #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 ...
- C - Crazy Town
Problem description Crazy Town is a plane on which there are n infinite line roads. Each road is def ...
- A. Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation ...
- 【codeforces 499C】Crazy Town
[题目链接]:http://codeforces.com/problemset/problem/499/C [题意] 一个平面,被n条直线分成若干个块; 你在其中的某一块,然后你想要要到的终点在另外一 ...
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- CodeForces 716A Crazy Computer
题目链接:http://codeforces.com/problemset/problem/716/A 题目大意: 输入 n c, 第二行 n 个整数,c表示时间间隔 秒. 每个整数代表是第几秒.如果 ...
- Codeforces_499C:Crazy Town(计算几何)
题目链接 给出点A(x1,y1),B(x2,y2),和n条直线(ai,bi,ci,aix + biy + ci = 0),求A到B穿过多少条直线 枚举每条直线判断A.B是否在该直线两侧即可 #incl ...
随机推荐
- Kvm--02 安装centos6系统 ,kvm磁盘管理
目录 1.安装一个CentOS6的系统的虚拟主机 2.虚拟机的备份 3.企业案例: 4.Kvm磁盘管理 1.安装一个CentOS6的系统的虚拟主机 #上传一个CenOS6系统的镜像到/opt目录下 [ ...
- Wait and Click Element
Wait and Click Element [Documentation] 等待元素出现并单击元素 [Arguments] ${locator} Wait Until Element Is Visi ...
- BZOJ3227 [sdoi2008]红黑树
贪心什么的太神仙了( 老老实实dp于是就是沙茶题了 f[i][d][0/1]表示i个节点bh为d当前节点颜色白/黑[好好读题是真.. 转移一下然后就可以打表了( 由于我们发现这玩意很好卡有很好的性质( ...
- CF 49E Common ancestor
传送门 模拟赛T1就自闭了( 才不会说我是去刚T2了来着 感觉非常暴力的一个题? 出题人良心开大数据范围 n=100 还是原来的n^4*26算法我也是自闭了 不过貌似跑不到n^4? 真·大力出奇迹 一 ...
- 常用生物信息 ID 及转换方法
众多不同的数据库所采用的对 Gene 和 Protein 编号的 ID 也是不同的, 所以在使用不同数据库数据的时候需要进行 ID 转换. 常用数据库 ID ID 示例 ID 来源 ENSG00000 ...
- C# 枚举的声名和使用
namespace xxxxxx { public enum EnumTextHAlign { Left = , Center = , Right = } } using xxxxxx;
- sqlserver2008锁表语句详解(锁定数据库一个表)
锁定数据库的一个表 复制代码代码如下: SELECT * FROM table WITH (HOLDLOCK) 注意: 锁定数据库的一个表的区别 复制代码代码如下: SELECT * FROM tab ...
- STM32输入捕获TIM2四通道
相比于一通道,原子的例程里因为清了计数时间,所以要对程序进行修改. 记录上升沿后的计数,然后记录下降沿的计数.相减后计算高电平时间,对于定时器中断间隔的边界要分开处理. 这里因为我的接收机时间是1ms ...
- ckeditor实现WORD粘贴图片自动上传
自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...
- CF 1172E Nauuo and ODT ——LCT
题目:http://codeforces.com/contest/1172/problem/E LCT好题. 考虑对每个颜色求出 “不是该颜色的点组成的连通块的 siz2 之和” .每个颜色用 LCT ...