CCF CSP-202009-1 称检测点查询(C++)

  • Post author:
  • Post category:其他


在这里插入图片描述

在这里插入图片描述

#include <cstdio>
#include <algorithm>

using namespace std;


struct Station{
	int x;
	int y;
	int dis;
	int num;
};

bool cmp(Station s1, Station s2){
	if(s1.dis != s2.dis) return s1.dis < s2.dis;
	if(s1.num != s2.num) return s1.num < s2.num;
}
int main(){
	int n, locx, locy;
	scanf("%d %d %d", &n, &locx, &locy);
	
	Station s[n];
	for(int i=0; i<n; i++){
		scanf("%d %d", &s[i].x, &s[i].y);
		s[i].num = i + 1;
		s[i].dis = (s[i].x-locx)*(s[i].x-locx) + (s[i].y-locy)*(s[i].y-locy);
	}
	
	sort(s, s+n, cmp);
	
	for(int i=0; i<3; i++){
		printf("%d\n", s[i].num);
	}
	
	return 0;
}

简单排序题



版权声明:本文为weixin_45964844原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。