poj 2653

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define dd double
#define eps 1e-7
#define maxn 220000
int n;
struct P{
dd x,y;
}a[maxn];
dd mul(P a1,P a2,P c){
return (a1.x-a2.x)*(c.y-a2.y)-(a1.y-a2.y)*(c.x-a2.x);
}
bool cross(P a1,P a2,P b1,P b2){
if(min(a1.x,a2.x)<=max(b1.x,b2.x)&&min(b1.x,b2.x)<=max(a1.x,a2.x)&&min(a1.y,a2.y)<=max(b1.y,b2.y)&&min(b1.y,b2.y)<=max(a1.y,a2.y)&&mul(a1,a2,b1)*mul(a1,a2,b2)<eps&&mul(b1,b2,a1)*mul(b1,b2,a2)<eps)return 1;
return 0;
}
int qu[maxn][2];
int qn[2];
P make(dd x,dd y){
P ans;
ans.x=x;
ans.y=y;
return ans;
}
bool cos(int p,int i){
return cross(a[(p<<1)-2],a[(p<<1)-1],a[(i<<1)-2],a[(i<<1)-1]);
}
int main(){
while(scanf("%d",&n),n){
qn[0]=0;
for(int i=1;i<=n;i++)scanf("%lf%lf%lf%lf",&a[i*2-2].x,&a[i*2-2].y,&a[i*2-1].x,&a[i*2-1].y);
for(int i=1;i<=n;i++){
int j=i&1;
qn[j]=0;
for(int k=1;k<=qn[j^1];k++){
int p=qu[k][j^1];
if(!cos(p,i))qu[++qn[j]][j]=p;
}
qu[++qn[j]][j]=i;
}
printf("Top sticks: ");
for(int j=1;j<qn[n&1];j++)printf("%d, ",qu[j][n&1]);
printf("%d.\n",qu[qn[n&1]][n&1]);
}


}

poj 2653

上一篇:泰国行记四:甲米两日游,大象,大象


下一篇:Model&Animation