2020牛客寒假算法基础集训营2 D数三角

题目

在这里插入图片描述
在这里插入图片描述

思路

两边的平方和大于另一边 就是钝角三角形

代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long  ll;
struct pp
{
    ll x;
    ll y;
}f[510];
int check(pp d,pp e,pp f)
{
    ll a = labs(d.x - e.x)*labs(d.x - e.x) + labs(d.y - e.y)*labs(d.y - e.y);
    ll b = labs(d.x - f.x)*labs(d.x - f.x) + labs(d.y - f.y)*labs(d.y - f.y);
    ll c = labs(e.x - f.x)*labs(e.x - f.x) + labs(e.y - f.y)*labs(e.y - f.y);
    if(sqrt(a)+sqrt(b)>sqrt(c) && sqrt(a)+sqrt(c)>sqrt(b) && sqrt(c)+sqrt(b)>sqrt(a))
    {
        if(a+b-c<0 || a+c-b<0 || b+c-a<0)
            return 1;
        else
            return 0;
    }
    else
        return 0;
}
int main()
{
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld %lld",&f[i].x,&f[i].y);
    }
    for(int i=1;i<=n-2;i++)
    {
        for(int j=i+1;j<=n-1;j++)
        {
            for(int k=j+1;k<=n;k++)
            {
                if(check(f[i],f[j],f[k]))ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值