FZU 2148

题意:给出30个点,判断这些点组成凸四边形的数量;

思路:对于a,b,c,d,如果组成的是 凹四边形,他们的组成的三角形的面积就会存在S abc =  S abd + S acd + S bcd 的情况,所以直接判断是否会出现这种情况就行。


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 100 + 10;
#define INF 0x3f3f3f3f
int n;
struct Node
{
    double x,y;
}a[maxn];
double distances(Node x,Node y)
{
    return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));
}
double area(Node x,Node y,Node z)//叉积求三角形面积
{
    return fabs( (z.x - y.x) * (x.y - y.y) - (x.x - y.x) * (z.y - y.y) );
}
double b[maxn];
bool is_(Node t1,Node t2,Node t3,Node t4)
{
    b[0] = area(t1,t2,t3);b[1] = area(t1,t2,t4);b[2] = area(t1,t3,t4);b[3] = area(t2,t3,t4);
    sort(b,b + 4);
    if(b[3] == b[0] + b[1] + b[2])
        return false;
    return true;
}
int main()
{
//    freopen("ins.text","r",stdin);
    int Tcase;
    scanf("%d",&Tcase);
    for(int ii = 1; ii <= Tcase; ii ++)
    {
        scanf("%d",&n);
        for(int i = 1; i <= n; i ++)
            scanf("%lf%lf",&a[i].x,&a[i].y);
        int ans = 0;
        for(int i = 1; i <= n - 2; i ++)
        {
            for(int j = i + 1; j <= n - 1; j ++)
            {
                for(int x = j + 1; x <= n; x ++)
                {
                    for(int y = x + 1; y <= n; y ++)
                    {
                        if(is_(a[i],a[j],a[x],a[y]))
                            ans ++;
                    }
                }
            }
        }
        printf("Case %d: ",ii);
        cout << ans << endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值