Bingo » 日志 » That Nice Euler Circuit & What's your Logo?
That Nice Euler Circuit & What's your Logo?
xiaoB.M. 发表于 2007-08-28 00:09:17
下面是That Nice Euler Circuit 的 主函数:
Point p[MAX_N];
Line l[MAX_N];
Point pp[MAX_N];
int n,nP;
int main()
{
int i,j,tmp;
int ans,Case;
Case = 1;
while(scanf("%d",&n),n)
{
for(i=0;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
//p[n] = p[0];
for(i=0;i<n-1;i++)
{
l[i].p1 = p[i];
l[i].p2 = p[i+1];
}
ans = 0;
for(i=0;i<n-1;i++)
{
nP = 0;
for(j=0;j<i;j++)
{
if(LineSegIntersect(l[i],l[j]))
{
Point tmpP;
if(CalCrossPoint(l[i],l[j],tmpP)==COLINE)
{
if(l[i].p1 == l[j].p2 || l[i].p1 == l[j].p1) continue;
else tmpP = l[i].p2;
}
if(tmpP == l[i].p1) continue;
pp[nP++] = tmpP;
}
}
sort(pp,pp+nP,cmp);
ans += nP;
for(j=1;j<nP;j++)
{
if(pp[j] == pp[j-1])
{
ans--;
}
}
}
printf("Case %d: There are %d pieces.\n",Case++,ans+1);
}
return 0;
}
