CCF202009-1 称检测点查询

  • Post author:
  • Post category:其他


100

# include <iostream>
# include <algorithm>
# include <cstring>

using namespace std;

int n,x,y;
int d[3],no[3],dist;

int main(void) {
	cin>>n>>x>>y;

	memset(d,0x3f,sizeof d);

	int a,b;
	for(int i=1; i<=n; i++) {
		cin>>a>>b;
		dist=(x-a)*(x-a)+(y-b)*(y-b);

		if(dist<d[0]) {
			no[2]=no[1];
			no[1]=no[0];
			no[0]=i;

			d[2]=d[1];
			d[1]=d[0];
			d[0]=dist;
		} else if(dist<d[1]) {
			no[2]=no[1];
			no[1]=i;

			d[2]=d[1];
			d[1]=dist;
		} else if(dist<d[2]) {
			no[2]=i;

			d[2]=dist;
		}
	}

	cout<<no[0]<<endl<<no[1]<<endl<<no[2]<<endl;

	return 0;
}

debug:

1.初始化;

2.
no\left [ i \right ]

d\left [ i \right ]
同时变化



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