链接

枚举两点(端点),循环遍历与直线相交的线段。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 105
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y = ):x(x),y(y){}
}p[N<<];
struct line
{
point a,b;
};
typedef point pointt ;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
double xmult(point a,point b,point c)
{
return cross(a-c,b-c);
}
int dotline(point p,line l)
{
return (!dcmp(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;
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
int Intersection( point a,point b,point c,point d )
{
int d1,d2;
d1 = dcmp(xmult( a,c,b ));
d2 = dcmp(xmult( a,d,b ));
if( d1*d2==- ) return ;//规范相交
if( d1==||d2== ) return ;//非规范相交
return ;//不相交
}
int main()
{
int t,i,j,n,g;
cin>>t;
while(t--)
{
cin>>n;
for(i= ; i <= n; i++)
{
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i+n].x,&p[i+n].y);
}
if(n==||n==)
{
puts("Yes!");
continue;
}
int flag = ;
for(i = ; i <= *n; i++)
{
for(j = i+; j<= *n; j++)
{
line l1;
l1.a = p[i],l1.b = p[j];
if(dcmp(dis(p[i]-p[j]))==) continue;
int num = ;
for(g = ; g <= n ;g++)
{
if(Intersection(p[i],p[j],p[g],p[g+n])) num++;
else break;
}
if(num==n)
{
flag = ;
break;
}
}
if(flag) break;
}
if(flag) puts("Yes!");
else puts("No!");
}
return ;
}

poj3304Segments(直线与多条线段相交)的更多相关文章

  1. (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)

    称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...

  2. POJ 3304 Segments (直线和线段相交判断)

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7739   Accepted: 2316 Descript ...

  3. POJ 3304 Segments(计算几何:直线与线段相交)

    POJ 3304 Segments 大意:给你一些线段,找出一条直线可以穿过全部的线段,相交包含端点. 思路:遍历全部的端点,取两个点形成直线,推断直线是否与全部线段相交,假设存在这种直线,输出Yes ...

  4. POJ 1066 Treasure Hunt(线段相交判断)

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4797   Accepted: 1998 Des ...

  5. POJ 3304 Segments (叉乘判断线段相交)

    <题目链接> 题目大意: 给出一些线段,判断是存在直线,使得该直线能够经过所有的线段.. 解题思路: 如果有存在这样的直线,过投影相交区域作直线的垂线,该垂线必定与每条线段相交,问题转化为 ...

  6. hdu 1558 (线段相交+并查集) Segment set

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1558 题意是在坐标系中,当输入P(注意是大写,我当开始就wa成了小写)的时候输入一条线段的起点坐标和终点坐 ...

  7. zoj 1010 Area【线段相交问题】

    链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 http://acm.hust.edu.cn/vjudge/ ...

  8. poj3304(是否存在一条直线与所有给出线段相交

    题意:给出n条线段,问你是否存在一条直线让他与所有线段相交. 思路:枚举两条直线的起点和终点做一条直线,看他是否与所有线段相交. #include<cstdio> #include< ...

  9. poj 3304 判断是否存在一条直线与所有线段相交

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8579   Accepted: 2608 Descript ...

随机推荐

  1. SlickGrid example 3a: 可编辑单元

    可编辑单元支持一列展示多个属性域,可以为编辑单元提供验证,并且自定义验证事件.   代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 T ...

  2. OracleHelper

    /// <summary> /// OracleServer数据库访问的通用工具类 /// </summary> public abstract class OracleHel ...

  3. CurrentHashMap的实现原理

    转载:http://wiki.jikexueyuan.com/project/java-collection/concurrenthashmap.html 概述 我们在之前的博文中了解到关于 Hash ...

  4. 越狱后如何添加cydia源及cydia源大全

    http://jingyan.baidu.com/article/6c67b1d6cc53fe2787bb1e06.html 软件游戏能PJ,插件其实也一样,所以有些源里面就包含了大量的PJ插件~ a ...

  5. nuget使用

    我如何获得的NuGet安装/更新的packages.config所有的软件包? nuget我有一个在它的多个项目的解决方案.大多数第三方引用的缺失,但也有packages.config文件为每个项目. ...

  6. mysql正则匹配解决查询一个字段是否在另一个字段中

    select b.filter_name , count(*) from at_goods a , at_search_filter bwhere a.application REGEXP b.fil ...

  7. Python if条件语句

    1. if 条件语句 if 条件: 内容1 内容2 else: 内容3 内容4 # 一个等号是赋值(=) # 两个等号是比较(==) #不等号(!=) #if 条件1 and 条件2(并且) #if ...

  8. Android 路径大全

    1 内部存储路径为/data/data/youPackageName/ 目录结构 //返回cache文件对象 this.getCacheDir(); //返回databases下指定文件 this.g ...

  9. HDU 4442 Physical Examination

    Physical Examination Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  10. CentOS 7下编译FreeSWITCH 1.6

    安装背景: 已经最小化安装CentOS 7. 准备工作: 挂载安装光盘,配置yum本地化安装,配置方法可以参考http://www.cnblogs.com/yoyotl/p/4877439.html. ...