FZU-2148-Moon Game

Moon Game

Accept: 789    Submit: 2362
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

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个点的坐标,问所有可能的四边形都多少个是 凸四边形。

题目链接:Moon Game

解题思路:
几何知识太匮乏了,这里一下就出现两个,感觉好强大~~~
之前已经学习过了,这里不再分析,发个链接:  (时空通道
判断四边形 凹凸 的方法 和 计算三角形面积 的方法 已经知道,而且数据 n <= 30 直接枚举出所有可能的四边形,然后 判断 凹凸 即可。
代码:
#include<cstdio>
#include<iostream>
#include<map>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<cstdlib>
#define si(x) scanf("%d",&x);
#define sii(x,y) scanf("%d%d",&x,&y);
#define siii(x,y,z) scanf("%d%d%d",&x,&y,&z);
#define rep(i,s,n) for(i = s;i <= n;i++)
#define dow(i,n,s) for(i = n;i >= s;i--)

using namespace std;
typedef long long LL;
int n,vex[35][2],s[5];

int area(int i,int j,int k)     //已知三点坐标求三角形面积,这里为了避免误差没有*1/2
{
    int t = vex[i][1] * vex[j][0] + vex[j][1] * vex[k][0] + vex[k][1] * vex[i][0];
    return vex[i][0] * vex[j][1] + vex[j][0] * vex[k][1] + vex[k][0] * vex[i][1] - t;
}
int main()
{
    int T,i,j,ans,cas = 1,k,l;
    si(T);
    while(T--) {
        si(n);
        rep(i,1,n) {
            scanf("%d %d",&vex[i][0],&vex[i][1]);
        }
        ans = 0;
        rep(i,1,n) {                    //枚举所有可能的四边形
            rep(j,i + 1,n) {
                rep(k,j + 1,n) {
                    rep(l,k + 1,n) {        
                        s[0] = abs(area(i,j,k) );
                        s[1] = abs(area(i,j,l) );
                        s[2] = abs(area(i,l,k) );
                        s[3] = abs(area(l,j,k) );
                        sort(s,s+4);
                        if(s[3] != s[0] + s[1] + s[2])  //凸四边形判断公式
                            ans++;
                    }
                }
            }
        }
        printf("Case %d: %d\n",cas++,ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值