PAT-乙-1082 1082 射击比赛 (20 分)

代码

#include <stdio.h>
#include <math.h>

int main() {
	
	double min = 10000;
	double max = -1;
	
	int N;
	scanf("%d", &N);
	
	int minId;
	int maxId;
	
	for(int i=0; i<N; i++) {
		int id;
		double x, y;
		scanf("%d %lf %lf", &id, &x, &y);
		double dis = sqrt(x*x+y*y);
		if(dis>max){
			maxId = id;
			max = dis;
		}
		if(dis<min){
			minId = id;
			min = dis;
		}
	}
	
	printf("%04d %04d\n", minId, maxId);
	return 0;
}

注解

这种不需存储,就能找到最大最小值的方法,是很常用的。

结果

PAT-乙-1082 1082 射击比赛 (20 分)

相关文章:

  • 2021-06-01
  • 2022-12-23
  • 2021-07-26
  • 2022-01-16
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-15
  • 2021-08-19
  • 2021-12-16
  • 2021-07-25
  • 2022-12-23
  • 2021-06-17
  • 2021-08-30
相关资源
相似解决方案