A. Crazy Town
来源:互联网 发布:程序员的心理疾病 编辑:程序博客网 时间:2024/05/22 13:31
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 -120 1 01 0 0
2
1 1-1 -131 0 00 1 01 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):
这题想通后很简单,就是看A,B两点间的直线有几条,用零点法看是否一正一负就行。注意一点要分两种情况讨论,不然会爆__int64.
#include<stdio.h>
#include<string.h>
int main()
{
__int64 x1,y1,x2,y2,i,j,a,b,c;
int n,sum;
while(scanf("%I64d%I64d",&x1,&y1)!=EOF)
{
scanf("%I64d%I64d",&x2,&y2);
scanf("%d",&n);
sum=0;
for(i=1;i<=n;i++){
scanf("%I64d%I64d%I64d",&a,&b,&c);
if(a*x1+b*y1+c>0 && a*x2+b*y2+c<0){
sum++;continue;
}
if(a*x1+b*y1+c<0 && a*x2+b*y2+c>0){
sum++;continue;
}
}
printf("%d\n",sum);
}
}
- A. Crazy Town
- codeforces 498A crazy town
- codeforces 498 A Crazy Town
- CodeForces 498A Round #284 div1A(div2C) Crazy Town
- Codeforces Round #284 (Div. 1) A - Crazy Town
- CodeForces 498A-Crazy Town-简单计算几何
- codeforce499C - Crazy Town
- CodeForces 499C、Crazy Town
- [CodeForces498A]Crazy Town[几何][附简略证明]
- Codeforces #284 C. Crazy Town 几何
- Codeforces Round #284 (Div. 2) C. Crazy Town
- Codeforces Round #284 (Div. 2) C. Crazy Town
- Codeforces Round #284 (Div. 2) C. Crazy Town 数学
- Codeforces Round #284 (Div. 2) C. Crazy Town
- Codeforces 499C:Crazy Town(计算几何)
- crazy p to a
- A crazy day
- A crazy new program
- [LeetCode]Convert Sorted Array to Binary Search Tree
- KMP算法理解
- 所以收效很微小
- 【简单常用】NSDictionary
- C++实现查找字符串中的数字,并输出
- A. Crazy Town
- 数学技巧 ZigZag Conversion
- 第一次尝试Crack(逆向异或算法)
- 迫不及待的想要分享一个神器Codota
- oc初始化方法,便利构造器
- Linux中nginx
- PHP5 non-thread-safe和thread-safe的区别
- 判断是否允许使用相机
- Android 深入理解Android中的自定义属性