Codeforces Round #284 (Div. 2) C. Crazy Town
来源:互联网 发布:linux sd卡上 编辑:程序博客网 时间:2024/05/27 20:42
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equationaix + biy + ci = 0, whereai andbi 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 followingn lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106;|ai| + |bi| > 0) — the coefficients of the lineaix + biy + ci = 0, defining thei-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):
猜测一下发现,统计AB的连线段经过多少直线即可,通过直线方程取出两点,再用叉积
#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<iostream>#include<algorithm>#include<bitset>#include<climits>#include<list>#include<iomanip>using namespace std;struct point{double x,y;point(){}point(double x,double y){this->x=x;this->y=y;}point operator -(point one){return point(x-one.x,y-one.y);}double operator *(point one){return x*one.y-y*one.x;}friend istream & operator >>(istream &is,point &one){is>>one.x>>one.y;return is;}};struct line{double a,b,c;void cg(point &one,point &two){if(a==0){one.y=two.y=-c/b;one.x=1;two.x=2;}else if(b==0){one.x=two.x=-c/a;one.y=1;two.y=2;}else if(c==0){one=point(0,0);two=point(b,-a);}else{one=point(0,-c/b);two=point(-c/a,0);}}friend istream & operator >>(istream &is,line &one){is>>one.a>>one.b>>one.c;return is;}};bool isok(point one,point two,line three){point four,five;three.cg(four,five);return (one-four)*(five-four)*((two-four)*(five-four))<0;}int main(){point one,two;cin>>one>>two;int n,ans=0;cin>>n;while(n--){line t;cin>>t;if(isok(one,two,t))ans++;}cout<<ans;}
- 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 Round #284 (Div. 2) C. Crazy Town ACM解题报告(几何)
- Codeforces Round #284 (Div. 1) A - Crazy Town
- Codeforces #284 C. Crazy Town 几何
- CodeForces 499C、Crazy Town
- CodeForces 498A Round #284 div1A(div2C) Crazy Town
- 【Codeforces Round #372 (Div. 2)】Codeforces 716A Crazy Computer
- Codeforces 499C:Crazy Town(计算几何)
- codeforces 498A crazy town
- codeforces 498 A Crazy Town
- Codeforces Round #372 (Div. 2)A. Crazy Computer
- Codeforces Round #284 (Div. 2) C
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #372 (Div. 2) A.Crazy Computer/B. Complete the Word
- 从hadoop框架与MapReduce模式中谈海量数据处理
- 嗅探(被动嗅探)与ARP欺骗(主动嗅探)详解
- Apache Shiro 使用手册(二)Shiro 认证
- svn merge conflicts handle
- Eclipse中用Maven编译报错的解决方法
- Codeforces Round #284 (Div. 2) C. Crazy Town
- rman 连接本地或者远程数据库方法
- 图片拼接 群组聊天头像设置(田字型 品字型)
- Apache Shiro 退出
- 49-UIWindow原理
- leetcode 之Excel Sheet Column Title
- 50-main.storyboard底层,通过storyboard创建控制器
- 右键添加打开终端的命令
- 用EhCache缓存Shiro的本地会话,当用户没有安全退出就直接关闭浏览器,会话可能在缓存里孤立的问题。