链接

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

 #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. QQ空间开放平台开发教程-SDK和API的使用

    <?php /** * OpenAPI V3 SDK 示例代码,适用于大部分OpenAPI.如果是上传文件类OpenAPI,请参考本SDK包中的“Test_UploadFile.php”文件中的 ...

  2. js声明

    var a = 2; //我们习惯把这条语句当做一条声明 但是js引擎把它当做两条声明. var a; //在编译时执行  同时var a;存在提升 a = 2;//在运行是执行  赋值lhs不会提升 ...

  3. Djnago的一些零碎知识点

    1.TEMPLATE_DIRS relative to the project folder http://stackoverflow.com/questions/9856683/using-pyth ...

  4. Maya Calendar 分类: POJ 2015-06-11 21:44 12人阅读 评论(0) 收藏

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 70016   Accepted: 21547 D ...

  5. hiho(1081),SPFA最短路,(非主流写法)

    题目链接:http://hihocoder.com/problemset/problem/1081 SPFA求最短路,是不应-羁绊大神教我的,附上头像. 我第一次写SPFA,我用的vector存邻接表 ...

  6. 关于Filter的配置

    配置代码: <filter> <display-name>OneFilter</display-name>  <filter-name>OneFilte ...

  7. MSSQL删除字段时出现 服务器: 消息 5074,级别 16,状态 1,行 1 的解决办法

    有的朋友在做用户维护字段的界面时,肯定发现一个问题,当用脚本:ALTER TABLE 表名 DROP COLUMN 字段名进行删除字段的操作时,会出现“服务器: 消息 5074,级别 16,状态 1, ...

  8. 各Android版本的Linux内核表(待续)以及如何下载相应的android源码

    一.Android版本与Linux内核的关系 http://www.cnblogs.com/qiengo/archive/2012/07/16/2593234.html 英文名 中文名 Android ...

  9. _in、_out。。。

    _in 输入参数_out 输出参数_opt 参数是可选的,就是可以为NULL_ecount 所指向的缓存的元素个素 也就是括号里的数字

  10. VC++ 工程添加 Unicode Debug和Unicode Release编译支持

    转载:http://blog.csdn.net/djhdu/article/details/171766 转载:http://blog.163.com/long_lh/blog/static/2769 ...