Moon Game FZU - 2148(思维)

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


思维自己没有想到利用面积的做法真是吐血 凸多边形不好判断 凹多边形可以判断啊傻逼

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#define eps 1e-9
using namespace std;
struct P
{
    int x,y;
}p[50];
double area(P a, P b, P c)
{
     return a.x * b.y + c.x * a.y + b.x * c.y - c.x * b.y - a.x * c.y - b.x * a.y;
}//求三角形面积公式 
bool ok(P a,P b,P c,P d)
{
    double sum1 = fabs(area(a, b, d)) + fabs(area(a, c, d)) + fabs(area(b, c, d));
    double sum2 = fabs(area(a, b, c));
    if(sum1==sum2)return true;//表示是凹包 
    return false;
}
bool judge(P a,P b,P c,P d)
{
    if(ok(a,b,c,d))return false;
    if(ok(a,b,d,c))return false;
    if(ok(a,c,d,b))return false;
    if(ok(b,c,d,a))return false;
    return true;
}
int main()
{
    int t,cas=0;
    scanf("%d",&t);
    while(t--)
    {
        int n,ans=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d%d",&p[i].x,&p[i].y);
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
                for(int x=j+1;x<n;x++)
                    for(int y=x+1;y<n;y++)
                        if(judge(p[i],p[j],p[x],p[y]))//是凸包的话 
                            ans++;
        printf("Case %d: %d\n",++cas,ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值