成都预赛 Polar intersecting line segments 已知N个线段,判断是否相交 排序+划分区间
2010-09-15 21:04
489 查看
Polar intersecting line segments
Time Limit: 1000 MS Memory Limit: 65536 KDescription
In this problem, you are asked to determine if a set of line segments intersect.Input
The first line of input is a number c ≤ 20, the number of test cases. The first line of each test case is a number k ≤ 50000, the number of line segments. The following k lines each consist of two numbers to eight decimal places θ1, θ2 with 0 < θ1 < 2π and 0 < θ2 < 2π describing the line segment from (cos θ1, sin θ1) to (cos θ2, sin θ2). For each test case, all inputs points are distinct.Output
For each test case, you should output a single line containing “intersect” if any two of the k lines intersect and “do not intersect” otherwise. The endpoints of a line are considered to be part of the line.Sample Input
2 2 0 3.14159265 1.57079633 4.71238898 2 0 1.57079633 3.14159265 4.71238898
Sample Output
intersect do not intersect
Source
Northeast North-America 2009, practice contest#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double eps=1e-8;
struct Point
{
double x,y;//角度
};
Point a[50000+10];
int flag;
bool cmp(Point h,Point k)
{
if(h.x!=k.x) return h.x<k.x;
return h.y<k.y;
}
void check(int l,int r)
{
if(l>=r) return ;
if(flag==0) return ;
for(int i=l;i<=r;)
{
int j=i+1;
while(j<=r&&a[i].x<a[j].x&&a[j].y<a[i].y) j++;
check(i+1,j-1);
if(flag==0) return ;
if(j==r+1) return ;
if(a[i].y<a[j].x) i=j;
else
{
flag=0;
return ;
}
}
}
int main()
{
int ci;scanf("%d",&ci);
while(ci--)
{
int n;scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
if(a[i].x>a[i].y) swap(a[i].x,a[i].y);
}
sort(a,a+n,cmp);
flag=1;
check(0,n-1);
if(flag) printf("do not intersect/n");
else printf("intersect/n");
}
return 0;
}
相关文章推荐
- 成都预赛 Complex intersecting line segments 判断线段是否相交 包含端点
- 已知两线段的四点坐标,如何判断两线段是否相交的思路
- 已知两条线段端点,判断是否相交及交点
- NYOJ 1016 判断两线段是否相交
- 判断两条线段是否相交
- 判断两个线段是否相交
- 判断两条线段是否相交 计算几何
- 判断两根线段是否相交
- hdu 1558 Segment set 并查集 叉积判断线段是否相交
- 判断线段是否与圆相交模板
- poj 3304 Segments 【判断是否存在一条直线与所有线段相交】
- 判断两线段是否相交
- 德莱联盟(判断两个线段是否相交)
- 判断两个线段是否相交
- 判断两条线段是否相交
- 判断点是否在直线上或线段上 判断线段相交 点与多边形的位置关系
- 判断两线段是否相交
- 两条线段知道端点line1(x1,y1)(x2,y2)line2(x3,y3)(x4,y4),判断两条线段是否相交,交点坐标(x,y)
- Poj-1066 (判断线段与线段是否相交)
- 判断两条线段是否相交(三种算法)