POJ3304 segment(线段交判断)
来源:互联网 发布:网络屏蔽怎么破解 编辑:程序博客网 时间:2024/05/05 22:10
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>using namespace std;const double inf = 1e-8;int dcmp(double x){ if(fabs(x) < 1e-8) return 0; if(x < 0) return -1; return 1;//1为正,-1为负,0为等}struct point{ double x , y; point(double x = 0,double y= 0):x(x),y(y){}/************************************/};typedef point Vector;point operator + (const Vector &a , const Vector &b){ return Vector(a.x + b.x,a.y + b.y);}point operator - (const Vector &a , const Vector &b){ return Vector(a.x - b.x,a.y - b.y);}point operator * (const Vector &a , const double &p){ return Vector(a.x * p,a.y * p);}point operator / (const Vector &a , const double &p){ return Vector(a.x / p,a.y / p);}bool operator > (const point &a,const point &b){return a.x > b.x;}bool operator == (const point &a,const point &b){ return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) ==0;};double cross(const Vector &a ,const Vector &b){ return (a.x * b.y - a.y * b.x);}double cross(point a,point b,point o){ return (a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);}double dot(const Vector &a,const Vector &b){ return (a.x * a.y + b.x * b.y);}struct segment{ point s,e; segment(point a = point(0,0),point b = point(0,0)){ s = a;e = b; }};point pnt[300];segment seg[200];int cnt;int cases;int lnum ;bool OnSegment(point p,point a1,point a2){ return dcmp(cross(a1-p,a2-p))==0&&dcmp(dot(a1-p,a2-p))<0; //线段包含端点时改成<=}bool cancross(segment &a,segment &b){ //跨立实验 double c1 = cross(b.e - a.e , a.s - a.e) , c2 = cross(b.s - a.e , a.s - a.e), c3 = cross(a.e - b.e , b.s - b.e), c4 = cross(a.s - b.e , b.s - b.e); if(dcmp(c1)*dcmp(c2) < 0 && dcmp(c1)*dcmp(c2) < 0) return true; if(OnSegment(a.e,b.e,b.s)||OnSegment(a.s,b.e,b.s)||OnSegment(b.e,a.e,a.s)||OnSegment(b.s,a.e,a.s)) return true; return false;}bool judge(segment p){ point a(0,0) ,b(0,0); a = p.e; b = p.s; if(abs(a.x-b.x)<inf&&abs(a.y-b.y)<inf) return false; for(int i=0;i<lnum;++i) { if(cross(a,b,seg[i].s)*cross(a,b,seg[i].e)>inf) return false; } return true;}int main(){ double x1,y1,x2,y2; scanf("%d",&cases); while(cases --) { memset(seg,0,sizeof(seg)); memset(pnt,0,sizeof(pnt)); bool flag = false; scanf("%d",&lnum); for(int i = 0; i < lnum ;i++){ scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); pnt[2*i] = point(x1,y1); pnt[2*i+1] = point(x2,y2); seg[i] = segment(pnt[2*i],pnt[2*i+1]); } int i,j; if(lnum ==1 ) flag =true; for(i = 0; i <= 2*lnum-2 && flag == false;i++) for(j = i ; j <= 2*lnum-2 && flag == false;j++) if(judge(segment(pnt[i],pnt[j]))) flag = true; if(flag) printf("Yes!\n"); else printf("No!\n"); } return 0;}
0 0
- POJ3304 segment(线段交判断)
- poj3304(计算几何+线段求交)
- Segments(poj3304,判断线段与直线相交)
- poj3304-Segments-判断直线和线段是否相交
- poj3304 判断是否存在一条直线经过n条线段
- 跨立实验判断线段是否相交->POJ3304
- POJ3304(计算几何基础-判断线段与直线相交)
- POJ3304 计算几何--判断直线与线段相交
- 判断一堆线段两两相交
- poj 3304 判断线段与直线交
- poj3304——Segments(判断直线与多个线段相交)
- POJ3304---Segments (基础计算几何:叉积判断线段相交)
- POJ3304-线段与直线相交
- 待思考, poj3304 线段投影
- HDOJ 1558 Segment set(并查集 + 线段判交)
- HDU 1558 Segment set(判断线段相交+并查集)
- HDU1558 - Segment set 并查集 + 判断线段相交
- hdu1558 Segment set (判断线段相交+并查集)
- HDU 3415 Max Sum of Max-K-sub-sequence
- C# 数据类型学习
- VS2008中自定义C++工程模板与修改新建文件默认编码的办法
- ArrayList和LinkedList
- Java的GC机制
- POJ3304 segment(线段交判断)
- cas logout跳转到指定页面(带service)
- 黑马程序员--黑马程序员CEO方立勋致全体员工和同学们的公开信
- uva 110
- java中各种对象转换为JSON
- Codeforces Round #262 (Div. 2)解题报告
- hdu4968(矩阵快速幂)
- Linux(CentOS)下,DNAT和SNAT(分享IP)
- cas logout代码细节