题目大意:一次丢下去n根木棒,问那些木棒不被其他木棒压着,依次输出。
题目思路:叉积判断线段是否相交,吐槽下POJ数据真弱竟然没超时……
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<queue> #define INF 0x3f3f3f3f #define MAX 100005 struct node { double x1,y1,x2,y2; }point[MAX]; int vis[MAX],n; double Cross(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4) { double a=(x2-x1)*(y3-y1)-(x3-x1)*(y2-y1); double b=(x2-x1)*(y4-y1)-(x4-x1)*(y2-y1); return a*b; } void Solve() { for(int i=1;i<n;i++) { double x1=point[i].x1; double y1=point[i].y1; double x2=point[i].x2; double y2=point[i].y2; for(int j=i+1;j<=n;j++) { if(Cross(x1,y1,x2,y2,point[j].x1,point[j].y1,point[j].x2,point[j].y2)<=1e-10 && Cross(point[j].x1,point[j].y1,point[j].x2,point[j].y2,x1,y1,x2,y2)<=1e-10) { vis[i]=1; break; } } } printf("Top sticks: "); for(int i=1;i<n;i++) { if(!vis[i]) printf("%d, ",i); } printf("%d. ",n); } int main() { while(scanf("%d",&n),n) { for(int i=1;i<=n;i++) { scanf("%lf%lf%lf%lf",&point[i].x1,&point[i].y1,&point[i].x2,&point[i].y2); vis[i]=0; } Solve(); } return 0; }