FZU 2148 Moon Game(判断凸边形(凹边形))

原创 2016年06月01日 17:35:28

Moon Game

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

240 0100 00 100100 10040 0100 00 10010 10

Sample Output

Case 1: 1Case 2: 0

解题思路:

给你n个点,判断能形成多少个凸多边形。

由于给的数据很小,因此可以直接暴力所有的点,但是凸多边形不是很好判断,可以转换为判断是否为凹多边形。如果存在一点d使

得:Sabc=Sabd+Sacd+Sbcd,则为凹边形。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

const double eps = 1e-9;
struct Point{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y){} // 构造函数,方便代码编写
}po[35];
typedef Point Vector;  //从程序实现上,Vector只是Point的别名

//点-点=向量
Vector operator - (Vector A,Vector B){
    return Vector(A.x-B.x,A.y-B.y);
}

double Cross(Vector A,Vector B){
    return A.x*B.y - A.y*B.x;
}

double area(Point a, Point b, Point c){
     return Cross(b-a,c-a)/2;
}

bool check(Point a,Point b,Point c,Point 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(fabs(sum1 - sum2) < eps) return true;
    return false;
}

bool solve(Point a,Point b,Point c,Point d){
    if(check(a,b,c,d)) return false;
    if(check(a,b,d,c)) return false;
    if(check(a,c,d,b)) return false;
    if(check(b,c,d,a)) return false;
    return true;
}

int main(){
    int T,t = 1;
    scanf("%d",&T);
    while(T--){
        int n,ans = 0;
        scanf("%d",&n);
        for(int i = 0; i < n; ++i)
            scanf("%lf%lf",&po[i].x,&po[i].y);
        for(int i = 0; i < n; ++i)
            for(int j = i+1; j < n; ++j)
                for(int k = j+1; k < n; ++k)
                    for(int l = k+1; l < n; ++l)
                        if(solve(po[i],po[j],po[k],po[l]))
                            ans++;
        printf("Case %d: %d\n",t++,ans);
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

区域赛选拔题--Moon Game--计算几何&&判断平面点集组成的凸边行的个数

【题意】给出平面的一系列的点的坐标,求其中组成凸边形的个数

【判断点在不在三角形内】FZU 2148 Moon Game

Problem Description 给你T组测试数据,每组测试数据给你一个n,接下来有n组,每组有代表一个坐标分别为两个正整数,问你能构成几个不是凹的四边形。 思路:核心考点,如何判断点在不在...

FZU 2148: Moon Game 四边形的月亮

原题链接:Moon Game 题目大意:给定一些点,判断能够构成多少个凸多边形 大致思路:对于给定的四个点A、B、C、D,如果没有一个点在其他三个点构成的三角形内部,则A、B、C、D四个点构成一个凸...

FZU - 2148 Moon Game

Description Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue ...

FZU2148 Moon Game(简单的计算几何)

题意        在一个平面中,给你N个点的坐标,请计算出一共能组成多少个凸四边形(convex quadrilateral)。 - - - - - - - - - - - - - - - - ...

FZU 2148 Moon Game(暴力+几何)

题目大意: 给出n个点,判断可以组成多少个凸四边形。 解题思路: 因为n很小,所以直接暴力,判断是否为凸四边形的方法是: 如果4个点中存在某个点D,Sabd + Sacd + Sbcd =...

FZU_ Problem 2148 Moon Game

Problem 2148 Moon Game Accept: 386    Submit: 1080 Time Limit: 1000 mSec    Memory Limit : 32768 KB...

I - Moon Game FZU - 2148

这个题的意思是给你n个点, 你判断下这n个点能组成几个凸面四边形。这个题的核心就是凸面四边形的组成条件。如果三个点,任意三个点组成三角形,第四个点在三角形的外部,那么就是凸面四边形。 如果一个点P在...
  • deerly_
  • deerly_
  • 2017年05月22日 09:44
  • 73

凸边形最优三角剖分问题

参考博客:草滩小恪的博客园   网址:http://www.cnblogs.com/acm1314/p/4574606.html

凸边形外壳

Problem Description Maxwell is a naughty boy. One day, he fouled the white and clean wall with in...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:FZU 2148 Moon Game(判断凸边形(凹边形))
举报原因:
原因补充:

(最多只允许输入30个字)