FZU 2148 Moon Game 判断凸边形

点击打开链接

Problem 2148 Moon Game

Accept: 512    Submit: 1419

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

240 0100 00 100100 10040 0100 00 10010 10

 Sample Output

Case 1: 1Case 2: 0

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

直接暴力所有的点,凸多边形不好判断,可以判断凹多边形,如果存在一点d:Sabc=Sabd+Sacd+Sbcd,则为凸边形。

//140 ms	216KB
#include<stdio.h>
#include<math.h>
#define eps 1e-9
struct P
{
    int x,y;
}p[1007];
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=1;
    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;
}
时间: 2024-07-29 04:42:47

FZU 2148 Moon Game 判断凸边形的相关文章

【暴力+排除法】FZU 2148 Moon Game

比赛地址:点击打开链接 比赛做粗的4个题几乎都是水,感觉弱的水爆炸了. 这个题最初的思路是枚举找出四个点,做凸多边形的模板判断.C(30,4). 结果答案不对..后来发现模板上是要求点对的顺序是逆时针或顺时针输入. 于是用时钟排序的函数排序后判断: bool cmp(point p1, point p2) { return atan2(p1.y, p1.x) < atan2(p2.y, p2.x); } 结果tle了两遍.. 最后发现其实不用模板上这样.可以用判断是不是凹多边形的办法,反正总体是

ACM: FZU 2148 Moon Game - 海伦公式

FZU 2148  Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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-dimensio

FZU 2148 Moon Game --判凹包

题意:给一些点,问这些点能够构成多少个凸四边形 做法: 1.直接判凸包 2.逆向思维,判凹包,不是凹包就是凸包了 怎样的四边形才是凹四边形呢?凹四边形总有一点在三个顶点的内部,假如顶点为A,B,C,D,则构成四个三角形:ABC,ACD,ABD,BCD,假如某一个三角形(最外的三个顶点)的面积等于另三个三角形面积之和,则是凹四边形. 然后做四个for循环,枚举即可,因为N最多才30. 代码: #include <iostream> #include <cstdio> #include

FZU 2148 Moon Game (枚举+几何)

 Problem 2148 Moon Game Accept: 403    Submit: 1126Time 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

FZU 2148 Moon Game

Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 2148 Description Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as

FZU 2148 moon game (计算几何判断凸包)

Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status 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-dime

FZU Problem 2148 Moon Game (判断凸四边形)

题目链接 题意 : 给你n个点,判断能形成多少个凸四边形. 思路 :如果形成凹四边形的话,说明一个点在另外三个点连成的三角形内部,这样,只要判断这个内部的点与另外三个点中每两个点相连组成的三个三角形的面积和要与另外三个点组成的三角形面积相同. 中途忘了加fabs还错了好几次 1 //FZU2148 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <cmath>

FZU_ Problem 2148 Moon Game

 Problem 2148 Moon Game Accept: 386    Submit: 1080 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

A Round Peg in a Ground Hole POJ - 1584(凸边形与圆相交)

A Round Peg in a Ground Hole POJ - 1584 题目链接:https://vjudge.net/problem/POJ-1584#author=0 题意:要求钉子要钉入孔内,判断能否在指定点钉入 思路:先判断这些点围成的多边形是不是凸多边形,如果是那么判断圆是否在凸边形里,若在那么就输出“PEG WILL FIT“,不在凸边形里就输出“PEG WILL NOT FIT”,如果都不是凸边形那么输出“HOLE IS ILL-FORMED” // // Created