题意:
一次投放一条木棍,问投放n次夹在上面的木棍有多小,并按顺序输出。
按顺序判断线段相交,线段相交,和直线与线段相交多个一个反正判断水题一个。
代码:
#include<cstdio>
#define eps 1e-8
using namespace std;
struct node{
double x,y;
}point[400005];
int rec[1005];
int cnt;
double Judge(node a,node b,node c){
return(a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
bool Iscross(int a){
double t1,t2,t3,t4;
for(int i=a+2;i<=cnt;i+=2){
t1=Judge(point[a],point[a+1],point[i]);
t2=Judge(point[a],point[a+1],point[i+1]);
t3=Judge(point[i],point[i+1],point[a]); //反正判断
t4=Judge(point[i],point[i+1],point[a+1]);
if((t1*t2)<-eps&&(t3*t4)<-eps) return false;
}
return true;
}
int main()
{
int n,i,p;
double x1,y1,x2,y2;
while(scanf("%d",&n)&&n){
cnt=p=0;
while(n--){
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
cnt++;
point[cnt].x=x1,point[cnt].y=y1;
cnt++;
point[cnt].x=x2,point[cnt].y=y2;
}
for(i=1;i<=cnt;i+=2)
if(Iscross(i)) rec[p++]=(i+1)>>1;
printf("Top sticks: ");
for(i=0;i<p;i++){
if(i==p-1) printf("%d.",rec[i]);
else printf("%d, ",rec[i]);
}
printf("\n");
}
}