I - Moon Game

Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a kind of two-dimensional plane. Then Fat brother starts to draw N starts in the sky which we can just consider each as a point. After he draws these stars, he starts to sing the famous song “The Moon Represents My Heart” to Maze.

You ask me how deeply I love you,

How much I love you?

My heart is true,

My love is true,

The moon represents my heart.

But as Fat brother is a little bit stay-adorable(呆萌), he just consider that the moon is a special kind of convex quadrilateral and starts to count the number of different convex quadrilateral in the sky. As this number is quiet large, he asks for your help.

Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains an integer N describe the number of the points.

Then N lines follow, Each line contains two integers describe the coordinate of the point, you can assume that no two points lie in a same coordinate and no three points lie in a same line. The coordinate of the point is in the range[-10086,10086].

1 <= T <=100, 1 <= N <= 30

Output

For each case, output the case number first, and then output the number of different convex quadrilateral in the sky. Two convex quadrilaterals are considered different if they lie in the different position in the sky.

Sample Input

2
4
0 0
100 0
0 100
100 100
4
0 0
100 0
0 100
10 10

Sample Output

Case 1: 1
Case 2: 0

题解:先用结构体保存每一个点,然后用四重循环把每一个组合都遍历到,然后因为四边形分凸和凹,我们算凹的,循环四次假设每一个点为内点,然后算内点到其他点的三角形的面积相加为总的三角形的面积,就能得出是内点,否则就不是,然后把不是凹的加起来就是凸的。因为算面积用的是double类型,所以会有一定的误差,所以要算上误差,大约0.01;

代码:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
using namespace std;

struct node
{
    int x,y;
}h[50],bd[4],aa,bb,cc,biao;

double kks(int x1,int y1,int x2,int y2,int x3,int y3)
{
    return (double)(0.5 * (double)abs(x2 * y3 + x1 * y2 + x3 * y1 - x3 * y2 - x2 * y1 - x1 * y3));
}

int main()
{
    int a,b,c,d,e,f,g,i,k,m,j;
    double ii,jj,kk,ll;
    scanf("%d",&a);
    for(b=1;b<=a;b++)
    {
        scanf("%d",&c);
        for(d=1;d<=c;d++)
        {
            scanf("%d %d",&h[d].x,&h[d].y);
        }
        k=0;
        for(e=1;e<=c;e++)
        {
            for(f=e+1;f<=c;f++)
            {
                for(g=f+1;g<=c;g++)
                {
                    for(i=g+1;i<=c;i++)
                    {
                        bd[0]=h[e],bd[1]=h[f],bd[2]=h[g],bd[3]=h[i];
                        j=0;
                        for(m=0;m<4;m++)
                        {
                            biao=bd[m];
                            aa=bd[(m+1)%4];
                            bb=bd[(m+2)%4];
                            cc=bd[(m+3)%4];
                            ii=kks(biao.x,biao.y,aa.x,aa.y,bb.x,bb.y);
                            jj=kks(biao.x,biao.y,aa.x,aa.y,cc.x,cc.y);
                            kk=kks(biao.x,biao.y,bb.x,bb.y,cc.x,cc.y);
                            ll=kks(bb.x,bb.y,aa.x,aa.y,cc.x,cc.y);
                            if((ii+jj+kk)-ll<0.01)
                                j++;
                        }
                       if(j==0)
                            k++;
                    }
                }
            }
        }
        printf("Case %d: %d\n",b,k);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/the_city_of_the__sky/article/details/81210363