Codeforces 618C Constellation

题目链接:http://codeforces.com/problemset/problem/618/C



题意:给出n个点,要求以这些点构造一个三角形,三角形的边不能有其他点,三角形内也不可以有其他点



思路:用点的x坐标或者y坐标排序,以第一个和第二个点为三角形2个点,寻找第三个点,排序过后就排除了有其他点还在边上的情况了


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL long long
using namespace std;

struct Node
{
    LL x,y,pos;
}s[100030];

bool cmp(Node p,Node q)
{
    if (p.x!=q.x)return p.x<q.x;
    else return p.y<q.y;
}

int main()
{
    int n;
    while (scanf("%d",&n)!=EOF)
    {
        for (int i=0;i<n;i++)
        {
            scanf("%I64d%I64d",&s[i].x,&s[i].y);
            s[i].pos=i+1;
        }
        sort(s,s+n,cmp);

        for (int i=2;i<n;i++)
        {
            LL x1=s[0].x,y1=s[0].y;
            LL x2=s[1].x,y2=s[1].y;
            LL x3=s[i].x,y3=s[i].y;
            LL k1=(x1-x2)*(y1-y3);
            LL k2=(x1-x3)*(y1-y2);
            if ((k1!=k2))
            {
                printf("%I64d %I64d %I64d\n",s[0].pos,s[1].pos,s[i].pos);
                break;
            }
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值