CCF 202009-1 称检测点查询(C++)
作者:互联网
使用 结构体
struct
+ 自定义sort
轻松搞定
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int n, X, Y;
struct point {
int i;
int dist;
}po[205];
bool cmp(point a, point b){
if (a.dist==b.dist)
return a.i < b.i;
return a.dist < b.dist;
}
int main()
{
cin >> n >> X >> Y;
for (int i = 1; i < n+1; i++){
int x, y;
scanf("%d %d", &x, &y);
po[i-1].i = i;
po[i-1].dist = pow(X-x, 2)+pow(Y-y, 2);
}
sort(po, po+n, cmp);
for (int i = 0; i < 3; i++){
printf("%d\n", po[i].i);
}
return 0;
}
标签:检测点,dist,point,int,C++,include,return,CCF,po 来源: https://www.cnblogs.com/understanding-friends/p/16637057.html