CodeForces 618C Constellation

传送门:http://codeforces.com/problemset/problem/618/C


已知若干的点的坐标,并且没有两个点坐标相同,所有点不会均在一条线上,求三个顶点构成的任意一个三角形,是其余的点都严格在三角形外。


水题。。。结果因为数据范围WA了

A1:按极角排序,所以第一个点,第二个点,和之后第一个不共线的点就是答案,因为数据范围,所以算叉乘的时候要用long long

A2:按坐标排序,先排x再排y,选点同上


代码如下:

#include<cstdio>
#include<algorithm>

using namespace std;

struct star
{
    long long x,y;
    int no;
};

    star s[100005];
    int now;
    int n;

long long angle(star a,star b,star c)
{
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}

long long dist(star a,star b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

bool cmp(const star a,const star b)
{
    long long t=angle(s[1],a,b);
    if (t>0)
    {
        return 1;
    }
    if (t<0)
    {
        return 0;
    }
    return dist(s[1],a)<dist(s[1],b);
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%I64d%I64d",&s[i].x,&s[i].y);
        s[i].no=i;
    }
    now=1;
    for (int i=2;i<=n;i++)
    {
        if (s[i].x<s[now].x || ((s[i].x==s[now].x) && (s[i].y<s[now].y)))
        {
            now=i;
        }
    }
    s[n+1]=s[1];
    s[1]=s[now];
    s[now]=s[n+1];
    sort(s+2,s+n+1,cmp);

    for (int i=3;i<=n;i++)
    {
        if (angle(s[1],s[2],s[i])!=0)
        {
            printf("%d %d %d\n",s[1].no,s[2].no,s[i].no);
            break;
        }
    }

    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值