moon game(凸四边形)

题意:给出n个点,求能够成的凸四边形的个数,题目已给出任意三个点不会在一条线上。

链接:http://acm.fzu.edu.cn/problem.php?pid=2148

思路:凹四边形任意三个点构成的三边形的面积一定有一个等于其余三个之和。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
struct node
{
    double x,y;
}a[40];

double compute(node s, node d, node f)   //注意返回double型
{
    return fabs((s.x * d.y + d.x * f.y + f.x * s.y - s.x * f.y - d.x * s.y - f.x * d.y) / 2);
}

int main()
{
    int t,cnt=0;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        for(int i=0; i<n;i++)
            cin >> a[i].x >> a[i].y;
        int sum=0;
        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++)
                    {
                        double e = compute(a[i],a[j],a[k]);
                        double b = compute(a[l],a[j],a[k]);
                        double c = compute(a[i],a[l],a[k]);
                        double d = compute(a[i],a[j],a[l]);
                        if(fabs(e-b-c-d)<1e-9 ||fabs(b-e-c-d)<1e-9 ||fabs(c-e-b-d)<1e-9 ||fabs(d-e-b-c)<1e-9)
                        {
                            continue;
                        }
                            sum++;
                    }
                }
            }
        }
        cout << "Case "<< ++cnt << ": " << sum << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值