fzu 2148 Moon Game(计算几何)

http://acm.fzu.edu.cn/contest/problem.php?cid=134&sortid=9

 

#include<cstdio>

#include<cmath>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

struct Node

{

  double x,y;

};

Node node[50];

double xmult(double x0,double y0,double x1,double y1,double x2,double y2)

{

  return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);

}

double ss(double x1,double y1,double x2,double y2,double x3,double y3)

{

  return fabs(xmult(x1,y1,x2,y2,x3,y3))/2;

}

int main()

{

  int t,n;

  int i,j,k,l;

  int cas=1;

  scanf("%d",&t);

  while(t--)

  {

    int ans=0;

    scanf("%d",&n);

    for(i=0;i<n;i++)

    {

      scanf("%lf%lf",&node[i].x,&node[i].y);

    }

    if(n<=3)

    {

      printf("Case %d: 0\n",cas++);

      continue;

    }

    for(i=0;i<n-3;i++)

    {

      for(j=i+1;j<n-2;j++)

      {

        for(k=j+1;k<n-1;k++)

        {

          for(l=k+1;l<n;l++)

          {

            double s1=ss(node[i].x,node[i].y,node[j].x,node[j].y,node[k].x,node[k].y);

            double s2=ss(node[i].x,node[i].y,node[j].x,node[j].y,node[l].x,node[l].y);

            double s3=ss(node[l].x,node[l].y,node[j].x,node[j].y,node[k].x,node[k].y);

            double s4=ss(node[i].x,node[i].y,node[l].x,node[l].y,node[k].x,node[k].y);

            if(s1+s2+s3!=s4&&s1+s2+s4!=s3&&s1+s3+s4!=s2&&s2+s3+s4!=s1) ans++;

          }

        }

      }

    }

    printf("Case %d: ",cas++);

    printf("%d\n",ans);

  }

  return 0;

}

  

你可能感兴趣的:(game)