CSP_202009-1_称检测点查询


题目描述

方法暴力了点,但是主要就是学个语法。

#include 
#include 
#include  
#include 
#include 
#include 
#include 
#include 
using namespace std;

const int INF = 0x3f3f3f3f;

// id, dis
bool cmp (pair a, pair b) {
	if (a.second == b.second) {
		return a.first < b.first;
	} else {
		return a.second < b.second;
	}
}

int main() {
	int n, x, y;
	int x_p, y_p;
	vector> points;
	cin >> n >> x >> y;
	for (int i = 0; i < n; i++) {
		cin >> x_p >> y_p;
		int d = pow(x-x_p, 2) + pow(y-y_p, 2);
		auto pair = make_pair(i, d);
		points.push_back(pair);
	}
	sort(points.begin(), points.end(), cmp);
	for (int i =0; i<3; i++) {
		cout << points[i].first+1 << endl;
	}
	return 0;
}

相关