ccf csp 202009-1 称检测点查询

202009-1 称检测点查询

要从一堆点中,找出距离 ( x , y ) (x,y) (x,y)最近的3个点,直接定义一下排序规则,排序后输出前3个点的编号即可

#include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
void pt(){ cout<<'\n';}
template<class H, class ... T> void pt(H h,T... t){ cout<<" "<<h; pt(t...);}


const ll maxn = 1e6+10;
ll N,X,Y;
struct node{
    ll x,y,id;
    bool operator <(const node &o) const{
        ll d1 = (X - x)*(X - x) + (Y-y)*(Y-y);
        ll d2 = (X - o.x)*(X - o.x) + (Y-o.y)*(Y-o.y);
        if(d1 != d2) return d1 < d2;
        else return id < o.id;
    }
}p[maxn];
int main(){
    cin>>N>>X>>Y;
    for(int i = 1;i<=N;i++) {
        scanf("%lld %lld",&p[i].x,&p[i].y);
        p[i].id = i;
    }
    sort(p+1,p+N+1);
    for(int i = 1;i<=3;i++){
        printf("%lld\n",p[i].id);
    }


    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值