Segments--poj3304(判断直线与线段之间的关系)
2016-04-24 17:59
489 查看
http://poj.org/problem?id=3304
给你几条线段 然后 让你找到一条直线让他在这条直线上的映射有一个重合点
如果有这条直线的话 这个重合的部分的两个端点一定是某两条线段的端点
所以只需要枚举每个点连成的直线能不能跟所有的线段相交就行了
给你几条线段 然后 让你找到一条直线让他在这条直线上的映射有一个重合点
如果有这条直线的话 这个重合的部分的两个端点一定是某两条线段的端点
所以只需要枚举每个点连成的直线能不能跟所有的线段相交就行了
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> #include<math.h> #define N 200 const double ESP = 1e-8; struct Point { double x, y; Point(double x=0,double y=0):x(x),y(y) {} Point operator + (const Point &temp)const{ return Point(x+temp.x, y+temp.y); } Point operator - (const Point &temp)const{ return Point(x-temp.x, y-temp.y); } bool operator == (const Point &temp)const{ return (fabs(x-temp.x) < ESP && fabs(y-temp.y) < ESP); } int operator * (const Point &temp)const{ double t=(x*temp.y)-(y*temp.x); if(t > ESP) return 1; if(fabs(t) < ESP) return 0; return -1; } }; struct node { Point A,B; node(Point A=0,Point B=0):A(A),B(B){} }; int Find(node t,node a[],int n) { for(int i=0;i<n;i++) { int k=fabs((a[i].A-t.A)*(t.B-t.A)+(a[i].B-t.A)*(t.B-t.A)); if(k==2) return false; } return true; } int main() { int n, T; scanf("%d", &T); while(T--) { Point p ; node a ; scanf("%d", &n); double x1,x2,y2,y1; int b=0; for(int i=0;i<n;i++) { scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2); p[b++]=Point(x1,y1); p[b++]=Point(x2,y2); a[i]=node(p[b-2],p[b-1]); } int ok=0; for(int i=0; i<b && !ok; i++) { for(int j=i+1; j<b && !ok; j++) { if(p[i] == p[j]) continue; ok = Find(node(p[i],p[j]),a,n); } } if(ok) printf("Yes!\n"); else printf("No!\n"); } return 0; }
相关文章推荐
- 一个Activity管理多个Fragment切换
- mac下的adt-bundle如何配置jre
- 实用资源推荐分享
- velocity 新手入门
- 用字符串做一个文本编译器
- CV和Resume的区别(转)
- Mysql学习
- linux命令**50
- View的事件体系之--View的弹性滑动Scroller
- 瑞昱RTL8710对标乐鑫ESP8266 谁将成为物联网首选-新版
- HM编码器代码阅读(22)——熵编码的初始化
- 工作总结07
- Mysql 设置utf-8 真正一劳永逸的方法
- 正则表达式生成器
- C++ Leetcode 111Minimum Depth of Binary Tree
- 《软件工程》第八周学习进度
- React学习笔记---生产周期方法
- Android Studio引用Library与导入jar
- html5表单相关属性以及运用
- scala 在vim中的语法高亮