POJ 1127 Jack Straws(计算几何)
2013-10-11 16:41
344 查看
题目链接
抄的模版,居然1Y了。就是简单的线段相交+并查集。
抄的模版,居然1Y了。就是简单的线段相交+并查集。
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> using namespace std; #define eps 1e-8 #define zero(x) (((x) > 0?(x):(-x))<eps) struct point { double x,y; }; struct line { point a,b; }; int o[100]; line p[101]; int xmult(point p1,point p2,point p0) { return (p1.x-p0.x)*(p2.y-p0.y) - (p1.y-p0.y)*(p2.x-p0.x); } int dot_online_in(point p,line l) { return zero(xmult(p,l.a,l.b))&&(l.a.x-p.x)*(l.b.x-p.x) < eps&&(l.a.y-p.y)*(l.b.y-p.y) < eps; } int dots_online(point p1,point p2,point p3) { return zero(xmult(p1,p2,p3)); } int same_side(point p1,point p2,line l) { return xmult(l.a,p1,l.b)*xmult(l.a,p2,l.b) > eps; } int interset_in(line u,line v) { if(!dots_online(u.a,u.b,v.a)||!dots_online(u.a,u.b,v.b)) return !same_side(u.a,u.b,v)&&!same_side(v.a,v.b,u); return dot_online_in(u.a,v)||dot_online_in(u.b,v)||dot_online_in(v.a,u)||dot_online_in(v.b,u); } int find(int x) { while(x != o[x]) x = o[x]; return x; } void merge(int x,int y) { x = find(x); y = find(y); if(x != y) o[x] = y; } int main() { int n,i,j,x,y; while(scanf("%d",&n)!=EOF) { if(n == 0) break; for(i = 1;i <= n;i ++) { o[i] = i; scanf("%lf%lf%lf%lf",&p[i].a.x,&p[i].a.y,&p[i].b.x,&p[i].b.y); } for(i = 1;i <= n;i ++) { for(j = i+1;j <= n;j ++) { if(interset_in(p[i],p[j])) merge(i,j); } } for(;;) { scanf("%d%d",&x,&y); if(x == 0&&y == 0) break; if(find(x) == find(y)) printf("CONNECTED\n"); else printf("NOT CONNECTED\n"); } } return 0; }
相关文章推荐
- poj 1127 Jack Straws(计算几何)
- POJ 1127-Jack Straws(计算几何 线段相交)
- POJ 1127 Jack Straws (计算几何)
- poj 1127 Jack Straws 计算几何 flod-warshall
- POJ 1127 Jack Straws [计算几何]
- 【计算几何】 POJ 1127 Jack Straws 判断线段是否相交
- POJ1127——Jack Straws(计算几何,直线相交)
- 【计算几何】 POJ 1127 Jack Straws 判断线段是否相交
- poj 1127 计算几何入门题 求线段交点
- POJ 1127 基础计算几何(判断两线段相交)+并查集
- POJ 1127 计算几何+并查集
- poj 1127 计算几何
- POJ 1127 —— 计算几何 && 线段相交
- POJ 1127 我的第一次计算几何
- poj 2031 Building a Space Station(计算几何+最小生成树)
- poj 3334 计算几何
- POJ 1410 Intersection 计算几何 判断线段与矩形位置
- POJ计算几何
- POJ 1039 Pipe 计算几何题目。。
- poj 1696:Space Ant(计算几何,凸包变种,极角排序)