Polar intersecting line segments
Time Limit: 1000 MS Memory Limit: 65536 K
Description
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;
}
Polar Line Segments Intersection
This program determines if a set of line segments in polar coordinates intersect. Given a number of line segments, the algorithm checks for intersections by sorting and analyzing angle ranges."
88409105,396712,Unity资源打包与压缩技巧,"['Unity开发', '游戏开发', '资源管理', '压缩技术', '打包策略']

被折叠的 条评论
为什么被折叠?



