CCF-CSP 202009-1称检测点查询

import javafx.print.Collation;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Scanner;
import java.util.Vector;
import java.math.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        //检测点总数
        int num=0;
        //居民坐标
        int[] People = new int[2];
        //获取输入
        String[] str = s.nextLine().split(" ");

        num = Integer.parseInt(str[0]);
        People[0]=Integer.parseInt(str[1]);
        People[1] = Integer.parseInt(str[2]);

        int[][] arr = new int[num][2];
        int index=0;
        while (index!=num){
            String[] temp = s.nextLine().split(" ");
            arr[index][0]= Integer.parseInt(temp[0]);
            arr[index][1]= Integer.parseInt(temp[1]);
            index++;
        }

        //创建一个Vector接收各个地方的距离
        Vector<Double> Length = new Vector<Double>();
        for(int i=0;i<num;i++){
            int x = (int) Math.pow((People[0]-arr[i][0]),2);
            int y = (int) Math.pow((People[1]-arr[i][1]),2);
            double ans =  Math.sqrt(x+y);
            Length.addElement(ans);
        }
        //此时获取前三个最近的编号的位置
        Vector<Double> Sort = new Vector<Double>();
        for(Double i:Length){
            Sort.addElement(i);
        }
        Collections.sort(Sort);
        //此时Length的前三个就是要求的 由于序号从1开始 故+1
        System.out.println(1+Length.indexOf(Sort.elementAt(0)));
        //为了以防重复 每次都将已经判断过的值化成最小值
        int local = Length.indexOf(Sort.elementAt(0));
        Length.set(local,Double.MIN_VALUE);
        System.out.println(1+Length.indexOf(Sort.elementAt(1)));
        local = Length.indexOf(Sort.elementAt(1));
        Length.set(local,Double.MIN_VALUE);
        System.out.println(1+Length.indexOf(Sort.elementAt(2)));
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值