FZU 2184 Moon Game(几何题)

本文介绍了一种算法,用于解决在给定点集中寻找不同凸四边形的问题。通过计算三角形面积并比较来判断四边形是否为凸,最终统计凸四边形的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  Moon Game

Accept: 372    Submit: 1042

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


题意:找凸四边形。判断是不是凸四边形,如果四边形有一个点在另外三个点组成的三角形内部,这个四边形就是凹四边形,否则就是凸四边形。
           另外,凹四边形内部那个点和其余任意两点可以组成三个三角形,这三个三角形面积的和恰好为外部三个点组成的三角形面积。
            多边形的面积公式:S = 0.5 * ( (x0*y1-x1*y0) + (x1*y2-x2*y1) + ... + (xn*y0-x0*yn) );


代码:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define MAXN 35
#define e 1e-7
struct point
{
    int x,y;
};
point p[MAXN];
double area(int a,int b,int c)
{
    return abs(p[a].x * p[b].y + p[c].x * p[a].y + p[b].x * p[c].y -
               p[c].x * p[b].y - p[a].x * p[c].y - p[b].x * p[a].y) * 0.5; //三角形面积公式
}
bool solve(int i,int j,int k,int m)
{
    double sum,a,b,c;
    sum=area(i,j,k);
    a=area(i,j,m);
    b=area(i,k,m);
    c=area(j,k,m);
    if(fabs(sum-a-b-c)<e)
        return false;
    sum=area(i,j,m);
    a=area(i,j,k);
    b=area(i,m,k);
    c=area(j,m,k);
    if(fabs(sum-a-b-c)<e)
        return false;
    sum=area(i,k,m);
    a=area(i,j,k);
    b=area(i,j,m);
    c=area(j,k,m);
    if(fabs(sum-a-b-c)<e)
        return false;
    sum=area(j,k,m);
    a=area(i,j,k);
    b=area(i,k,m);
    c=area(i,j,m);
    if(fabs(sum-a-b-c)<e)
        return false;
    return true;
}
int main()
{
    int t,n,m,i,j,k,ans,num=1;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ans=0;
        for(i=0; i<n; i++)
            cin>>p[i].x>>p[i].y;
        cout<<"Case "<<num++<<": ";
        for(i=0; i<n; i++)
        {
            for(j=i+1; j<n; j++)
            {
                for(k=j+1; k<n; k++)
                {
                    for(m=k+1; m<n; m++)
                    {
                        if(solve(i,j,k,m))
                            ans++;
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}














评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值