CSP-202009-1-称检测点查询
解题思路
- 本题的时间复杂度貌似没有限制,直接暴力枚举就能
- 知识盲点:
sort()
函数-升序排序#include <algorithm>
- 给名为dis,长度为n的数组排序
sort(new_dis, new_dis + n);
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n, x, y, flag = 0, dis[205] = {}, new_dis[205] = {};
cin >> n >> x >> y;
for (int i = 0; i < n; i++)
{
int xi, yi;
cin >> xi >> yi;
dis[i] = (x - xi) * (x - xi) + (y - yi) * (y - yi);
new_dis[i] = dis[i];
}
// 升序排序
sort(new_dis, new_dis + n);
int min = new_dis[0];
bool isChange = 1;
for (int i = 0; i < n; i++)
{
if (new_dis[i] != min)
{
min = new_dis[i];
isChange = 1;
}
// new_dis可能有重复值,不检查相同的值
if (isChange)
{
for (int j = 0; j < n; j++)
{
if (dis[j] == min)
{
cout << j + 1 << endl;
flag++;
}
if (flag == 3) break;
}
isChange = 0;
}
if (flag == 3) break;
}
return 0;
}