ccf csp 202009-1 称检测点查询

本文介绍了一种通过计算几何距离来找到离指定坐标(x,y)最近的三个点的方法。使用C++实现,包括输入坐标、计算各点到指定坐标的距离,并进行排序,最后输出最近的三个点的编号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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、付费专栏及课程。

余额充值