标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 11537 | Accepted: 4337 |
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
【思路】
暴力枚举+判断线段是否相交。
数据弱得一 哔~ <_<
【代码】
1 #include<cmath> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define FOR(a,b,c) for(int a=(b);a<=(c);a++) 6 using namespace std; 7 8 const int N = 100000+10; 9 const double eps = 1e-8; 10 int dcmp(double x) { 11 if(x<eps) return 0; else return x<0? -1:1; 12 } 13 14 struct Pt { 15 double x,y; 16 Pt (double x=0,double y=0):x(x),y(y) {}; 17 }; 18 struct Line { Pt a1,a2; 19 }; 20 typedef Pt vec; 21 vec operator - (Pt A,Pt B) { return vec(A.x-B.x,A.y-B.y); } 22 23 double cross(vec A,vec B) { return A.x*B.y-A.y*B.x; } 24 25 bool SegInter(Pt s1, Pt e1, Pt s2, Pt e2) { 26 if( min(s1.x, e1.x) <= max(s2.x, e2.x) && 27 min(s1.y, e1.y) <= max(s2.y, e2.y) && 28 min(s2.x, e2.x) <= max(s1.x, e1.x) && 29 min(s2.y, e2.y) <= max(s1.y, e1.y) && 30 cross(e1-s1,s2-s1) * cross(e1-s1,e2-s1) <= 0 && 31 cross(e2-s2,s1-s2) * cross(e2-s2,e1-s2) <= 0 32 ) return true; 33 return false; 34 } 35 36 int n; 37 Line L[N]; 38 39 int main() { 40 while(scanf("%d",&n)==1 && n) { 41 double x,y,x2,y2; 42 FOR(i,1,n) { 43 scanf("%lf%lf%lf%lf",&x,&y,&x2,&y2); 44 L[i].a1=Pt(x,y) , L[i].a2=Pt(x2,y2); 45 } 46 bool first=1; 47 printf("Top sticks:"); 48 FOR(i,1,n) { 49 bool flag=1; 50 FOR(j,i+1,n) 51 if(SegInter(L[i].a1,L[i].a2,L[j].a1,L[j].a2)) { 52 flag=0; break; 53 } 54 if(flag) { 55 if(first) first=0; else putchar(‘,‘); 56 printf(" %d",i); 57 } 58 } 59 puts("."); 60 } 61 return 0; 62 }
标签:
原文地址:http://www.cnblogs.com/lidaxin/p/5179292.html