标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 11335 | Accepted: 4250 |
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.
题解:这个题是让找出与其他直线不交或者在其他直线最上面的直线;
判断相交,两个直线的一个端点都要判断;
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #define mem(x,y) memset(x,y,sizeof(x)) 7 using namespace std; 8 typedef long long LL; 9 const int INF=0x3f3f3f3f; 10 const int MAXN=100010<<1; 11 struct Point{ 12 double x,y; 13 Point(double x=0,double y=0):x(x),y(y){} 14 }; 15 typedef Point Vector; 16 Point dt[MAXN]; 17 Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);} 18 double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;} 19 int main(){ 20 int n,k,j; 21 while(scanf("%d",&n),n){ 22 k=0; 23 for(int i=1;i<=n;i++) 24 scanf("%lf%lf%lf%lf",&dt[i].x,&dt[i].y,&dt[i+n].x,&dt[i+n].y); 25 printf("Top sticks: "); 26 for(int i=1;i<n;i++){ 27 for(j=i+1;j<=n;j++){ 28 if(Cross(dt[i]-dt[j],dt[i]-dt[j+n])*Cross(dt[i+n]-dt[j],dt[i+n]-dt[j+n])<=0) 29 if(Cross(dt[j]-dt[i],dt[j]-dt[i+n])*Cross(dt[j+n]-dt[i],dt[j+n]-dt[i+n])<=0) 30 break; 31 } 32 if(j==n+1)printf("%d, ",i); 33 } 34 printf("%d.\n",n); 35 } 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4946074.html