题意:n个线段,一个一个的放,问最后没有被压住的都有哪些(貌似不用考虑端点?题中没细说)
思路:n有点大,可以考虑用两个队列(不过比直接算慢了点,因为用了stl?),或者是直接算,如果没有和后面的相交就可以,否则跳过
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<list>
using namespace std;
const double INF = 1e200;
const double EP = 1e-8;
const int maxn = 100000+100;
const double PI = acos(-1);
struct POINT{///点 定义
double x;
double y;
POINT(double a = 0,double b = 0){x = a;y = b;}
};
struct SEGMENT{///line segment///线段 定义
POINT s;
POINT e;
SEGMENT(POINT a,POINT b){s = a;e = b;}
SEGMENT(){}
};
struct LINE{///ax + by + c = 0&&a >= 0///一般式
double a;
double b;
double c;
LINE(double da,double db,double dc){a = da;b = db;c = dc;}
LINE(double x1,double y1,double x2,double y2){///根据两个点求出一般式
a = y1 - y2;b = x2 - x1;c = x1*y2 - x2*y1;
if(a < 0){a*=-1;b*=-1;c*=-1;}
}
};
double multiply(POINT sp,POINT ep,POINT op){///向量op->sp X op->ep的叉乘,小于0:ep在op->sp顺时针方向//大于0:0:ep在op->sp逆时针方向//等于0:三点共线
return ((sp.x - op.x)*(ep.y - op.y) - (ep.x - op.x)*(sp.y - op.y));
}
bool online(SEGMENT l,POINT p){///判断点是否在线段上
return ((multiply(l.e,p,l.s) == 0)&&(((p.x-l.s.x)*(p.x-l.e.x))<= 0)&&(((p.y-l.s.y)*(p.y-l.e.y)) <= 0));
}
bool intersect(SEGMENT u,SEGMENT v){///两线段相交(包括端点),返回true
return ((max(u.s.x,u.e.x) >= min(v.s.x,v.e.x))&&
(max(v.s.x,v.e.x) >= min(u.s.x,u.e.x))&&
(max(u.s.y,u.e.y) >= min(v.s.y,v.e.y))&&
(max(v.s.y,v.e.y) >= min(u.s.y,u.e.y))&&
(multiply(v.s,u.e,u.s)*multiply(u.e,v.e,u.s) >= 0)&&
(multiply(u.s,v.e,v.s)*multiply(v.e,u.e,v.s) >= 0));
}
bool intersect_a(SEGMENT u,SEGMENT v){///两线段相交(不包括端点)
return ((intersect(u,v))&&
!online(u,v.s)&&
!online(u,v.e)&&
!online(v,u.e)&&
!online(v,u.s));
}
int lineintersect(LINE l1,LINE l2,POINT &p){///求两直线交点,有交点返回1和交点,没有返回0,重合返回2
double d = l1.a*l2.b-l2.a*l1.b;
double d2 = l1.a*l2.c-l2.a*l1.c;
double d3 = l1.b*l2.c-l2.b*l1.c;
if(fabs(d) < EP&&fabs(d2) < EP&&fabs(d3) < EP)return 2;
p.x = (l2.c*l1.b-l1.c*l2.b)/d;
p.y = (l2.a*l1.c-l1.a*l2.c)/d;
if(fabs(d) < EP)return 0;
return 1;
}
double point_dis(POINT a,POINT b){///求两点距离
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
///************************************************************************************************************************************
int n;
SEGMENT ss[maxn];
int main(){
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n)){
if(n == 0)break;
for(int i = 0;i < n;i ++){
double a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
POINT aa(a,b),bb(c,d);
ss[i].s = aa;ss[i].e = bb;
}
printf("Top sticks:");
for(int i = 0;i < n-1;i++){
bool flag = 1;
for(int j = i+1;j < n;j ++){
if(intersect(ss[i],ss[j])){
flag = 0;
break;
}
}
if(flag)printf(" %d,",i+1);
}
printf(" %d.\n",n);
}
return 0;
}