证明在这篇博客里https://blog.csdn.net/qq_43708222/article/details/99052341
#include<cstdio>
#include<cmath>
using namespace std;
const int N = 1e6 + 7;
double dx1[N];
double dx2[N];
double dy1[N];
double dy2[N];
double cal(double x1,double y1,double x2,double y2) {
return (x1 * y2) - (x2 * y1);
}
bool isIntersect(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4) {
double x = x2 - x1;
double y = y2 - y1;
double cal1 = cal(x3 - x1,y3 - y1,x,y);
double cal2 = cal(x4 - x1,y4 - y1,x,y);
if(cal1 * cal2 > 0) return false;
x = x4 - x3;
y = y4 - y3;
cal1 = cal(x1 - x3,y1 - y3,x,y);
cal2 = cal(x2 - x3,y2 - y3,x,y);
if(cal1 * cal2 > 0) return false;
return true;
}
int main() {
int n;
while(~scanf("%d",&n) && n) {
for(int i = 0; i < n; i++)
scanf("%lf%lf%lf%lf", &dx1[i], &dy1[i], &dx2[i], &dy2[i]);
bool flag;
printf("Top sticks: ");
for(int i = 0; i < n - 1; i++) {
flag = 0;
for(int j = i + 1; j < n; j++) {
if(isIntersect(dx1[i],dy1[i],dx2[i],dy2[i],dx1[j],dy1[j],dx2[j],dy2[j])) {
flag = 1;
break;
}
}
if(!flag) {
printf("%d, ",i + 1);
}
}
printf("%d.\n",n);
}
return 0;
}