【CCF】202009-1 称检测点查询(Java实现)

【CCF】202009-1 称检测点查询(Java实现)

试题编号: 202009-1
试题名称: 称检测点查询
时间限制: 1.0s
内存限制: 256.0MB
问题描述:
问题描述
样例输入1
3 2 2
2 2
2 3
2 4
样例输出1
1
2
3
样例输入2
5 0 1
-1 0
0 0
1 0
0 2
-1 2
样例输出2
2
4
1

思路

1.计算每一个检测点的距离
2.找出最近的三个检测点的编号
(困难在于,如何找出检测点及其对应编号)
解决思路如下:循环遍历三次存放距离的数组,找到最小的距离,输出编号,并将其值设置为Integer.MAX_VALUE,循环三次即可。

代码

import java.util.Scanner;

public class one_19 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int [] d = new int[n];
		for (int i = 0; i < n; i++) {
			int x1 = sc.nextInt();
			int y1 = sc.nextInt();
			d[i] = (x-x1)*(x-x1)+(y-y1)*(y-y1);
		}
		
		int [] treemin = new int[3];
		treemin[0] = Integer.MAX_VALUE;
		treemin[1] = Integer.MAX_VALUE;
		treemin[2] = Integer.MAX_VALUE;
		int [] minnum = new int[3];
		for (int j = 0; j < minnum.length; j++) {
			for (int i = 0; i < d.length; i++) {
				if (d[i]<treemin[j]) {
					treemin[j]=d[i];
					minnum[j]=i+1;
				}
			}
			System.out.println(minnum[j]);
			d[minnum[j]-1]=Integer.MAX_VALUE;
		}
	}

}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值