标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 10364 | Accepted: 3842 |
Description
Input
Output
Sample Input
5 1 1 4 2 2 3 3 1 1 -2.0 8 4 1 4 8 2 3 3 6 -2.0 3 0 0 1 1 1 0 2 1 2 0 3 1 0
Sample Output
Top sticks: 2, 4, 5. Top sticks: 1, 2, 3.
Hint
Source
/** 题意:给出n条线段,然后取没有被覆盖的; 做法:计算几何(线段相交) **/ #include <iostream> #include<cmath> #include<algorithm> #include<string.h> #include<stdio.h> #define maxn 100000+ 10 using namespace std; int n,m; int mmap[maxn]; const double eps = 1e-8; const double PI = acos(-1.0); int sgn(double x) { if(fabs(x) < eps) return 0; if(x < 0) return -1; return 1; } struct Point { double x; double y; Point() {} Point(double _x,double _y) { x = _x; y = _y; } Point operator - (const Point &b) const { return Point(x - b.x,y - b.y); } double operator ^(const Point &b) const { return x*b.y - y*b.x; } double operator *(const Point &b) const { return x*b.x + y*b.y; } } point[maxn]; struct Line { Point s; Point e; Line() {} Line(Point _s,Point _e) { s = _s; e = _e; } } line[maxn]; bool inter(Line l1,Line l2) { return max(l1.s.x ,l1.e.x) >= min(l2.s.x,l2.e.x) && max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) && max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) && max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) && sgn((l2.s - l1.e) ^(l1.s-l1.e) )*sgn((l2.e - l1.e)^(l1.s-l1.e) )<= 0 && sgn((l1.s - l2.e) ^(l2.s- l2.e)) *sgn((l1.e - l2.e) ^(l2.s - l2.e)) <=0; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE int n; while(~scanf("%d",&n)) { if(n == 0) break; double a,b,c,d; for(int i=0; i<n; i++) { scanf("%lf %lf %lf %lf",&a,&b,&c,&d); line[i] = Line(Point(a,b),Point(c,d)); } memset(mmap,0,sizeof(mmap)); for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) { if(inter(line[i],line[j])) { mmap[i] = 1; break; } } } printf("Top sticks: "); int res = 0; for(int i=0; i<n; i++) { if(mmap[i] == 0) { if(res != 0) printf(", "); printf("%d",i+1); res++; } } printf(".\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/chenyang920/p/4434432.html