FZU - 2148 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

題意:

       給出n個點座標,求一共可以組成多少個凸四邊形。

思路:

       由於測試量很小,完全可以所有點暴力枚舉,在判斷是否是凸四邊形時,可以利用叉積計算四個頂點中每三個頂點組成的三角形面積,如果不是凸四邊形,那麼最大的三角形面積一定是另外三個三角形面積之和。

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <deque>
#include <string>
#include <cmath>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <climits>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define INF 2147483647
using namespace std;
typedef long long ll;
int T,i,n,j,t,k,l;
struct PPoint
{
    int x,y;
} pp[35];
double Aarea(int a,int b,int c)
{
    double s=(double)(1.0/2)*(pp[a].x*pp[b].y+pp[b].x*pp[c].y+pp[c].x*pp[a].y-pp[a].x*pp[c].y-pp[b].x*pp[a].y-pp[c].x*pp[b].y);
    if(s<0) return -s;
    return s;
}

int main()
{
    scanf("%d",&T);
    for(t=1; t<=T; t++)
    {
        memset(pp,0,sizeof(pp));
        scanf("%d",&n);
        for(i=0; i<n; i++)
            scanf("%d%d",&pp[i].x,&pp[i].y);
        int res=0;
        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++)
                for(k=j+1; k<n; k++)
                    for(l=k+1; l<n; l++)
                    {
                        double are[10];
                        memset(are,0,sizeof(are));
                        are[0]=Aarea(i,j,k);
                        are[1]=Aarea(i,j,l);
                        are[2]=Aarea(j,k,l);
                        are[3]=Aarea(k,l,i);
                        sort(are,are+4);
                        if(are[3]-are[1]-are[2]-are[0]<0.01&&are[3]-are[1]-are[2]-are[0]>-0.01)
                                continue;
                        res++;
                    }
        printf("Case %d: %d\n",t,res);
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章