Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) C. Constellation(思维 简单几何)

题意:给你n个点(n<=1e5),保证所有点不在同一直线上,让你找三个点,形成一个三角形,且该三角形内没有点。


思路:先按x轴排序,x相同按y排序。因为保证所有点不在同一直线上,这样前两个必定可以和后面某个点构成三角形,且从第三个开始找第一个能形成三角形的内部一定没有其他点,因为如果有其他点,那这个内部点同样可以与前两个点形成三角形,且在这个点前面。


代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
struct node
{
    ll x, y;
    int id;
    bool operator < (const node &a) const
    {
        if(x == a.x) return y < a.y;
        return x < a.x;
    }
}a[maxn];

bool judge(node aa, node bb, node cc)
{
    return (cc.y-bb.y)*(bb.x-aa.x)!=(bb.y-aa.y)*(cc.x-bb.x);
}

int main(void)
{
    int n;
    while(cin >> n)
    {
        for(int i = 1; i <= n; i++)
            scanf("%d%d", &a[i].x, &a[i].y), a[i].id = i;
        sort(a+1, a+1+n);
        for(int i = 3; i <= n; i++)
            if(judge(a[1], a[2], a[i]))
            {
                printf("%d %d %d\n", a[1].id, a[2].id, a[i].id);
                break;
            }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值