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 ...
随机推荐
- 攻防世界--simple-unpack
下载链接:https://adworld.xctf.org.cn/media/task/attachments/b7cf4629544f4e759d690100c3f96caa 1.准备 获取到信息: ...
- oracle ALL视图
select * from ALL_ALL_TABLES -- 用户可存取的所有表. select * from ALL_BASE_TABLE_MVIEWS -- 用户可存取的所有物化视 ...
- 从零开始的PHP生活Day1
PHP 什么是PHP? PHP(Hypertext Preprocessor,超文本预处理器)是一种服务器端的.跨平台的.HTML嵌入式的弱类型开源脚本语言. 1.服务器端:PHP需要使用服务器软件进 ...
- django允许外部访问 项目后台不挂断运行
1关闭防火墙 1 service iptables stop 2设置django 1 2 3 4 5 6 7 8 9 10 11 开开启django时,使用0.0.0.0:xxxx,作为ip和端口例如 ...
- Codeforces Round #394 (Div. 2) - C
题目链接:http://codeforces.com/contest/761/problem/C 题意:给定n个长度为m的字符串.每个字符串(字符串下标从0到m-1)都有一个指针,初始指针指向第0个位 ...
- java两个引用指向同一个对象
- IText PDF简单示例
package com.exe.learn.demo.itextpdf; import java.io.ByteArrayInputStream; import java.io.File; impor ...
- 通过URL方式动态修改logback level级别
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.qos.logback.classic.Level; import ...
- Flutter中的日期、格式化日期、日期选择器组件
Flutter中的日期和时间戳 //獲取當前日期 DateTime _nowDate = DateTime.now(); print(_nowDate);//2019-10-29 10:57:20.3 ...
- React笔记02——React中的组件
一个网页可以被拆分成若干小部分,每个部分都可以称为组件,即组件是网页中的一部分.组件中还可以有多个组件. 上一节中的App.js就是一个组件(继承了React.Component类的类). 一个组件的 ...