zoukankan      html  css  js  c++  java
  • CSP认证2020-09-1-称检测点查询-(Java)100分

    称检测点查询

    问题描述

    试题编号: 202009-1
    试题名称: 称检测点查询
    时间限制: 1.0s
    内存限制: 256.0MB
    问题描述:
    题目背景

    2020 年 6 月 8 日,国务院联防联控机制发布《关于加快推进新冠病毒核酸检测的实施意见》,提出对“密切接触者”等八类重点人群“应检尽检”,其他人群“愿检尽检”。

    问题描述

    某市设有 n 个核酸检测点,编号从 1 到 n,其中 i 号检测点的位置可以表示为一个平面整数坐标 (x_i, y_i)。

    为方便预约核酸检测,请根据市民所在位置 (X, Y),查询距其最近的三个检测点。
    多个检测点距离相同时,编号较小的视为更近。

    输入格式

    输入共 n+1 行。

    第一行包含用空格分隔的三个整数 n、X 和 Y,表示检测点总数和市民所在位置。

    第二行到第 n+1 行依次输入 n 个检测点的坐标。第 i+1 行(1 < i < n)包含用空格分隔的两个整数 x_i 和 y_i,表示 i 号检测点所在位置。

    输出格式

    输出共三行,按距离从近到远,依次输出距离该市民最近的三个检测点编号。

    样例输入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

    样例2解释

    在这里插入图片描述
    评测用例规模与约定

    全部的测试点满足,3 < n < 200,所有坐标均为整数且绝对值不超过 1000。
    提示
    市民到第 i 号检测点的距离 D_i 可由如下公式算出:
    {{
    D_i^2 = (X - x_i)^2 + (Y - y_i)^2
    }}

    Java满分答案
    在这里插入图片描述
    代码如下:

    import java.util.Scanner;
    
    class Point{
        public int x;
        public int y;
        public int distancesq;
    }
    public class Main {
        public static void main(String [] args){
            Scanner sc = new Scanner(System.in);
            int sum = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            Point[] jcpoint = new Point[sum];
            int[] book = new int[3];
            int min1 = 1000001, min2 = 1000001, min3 = 1000001;
            for(int i = 0;i < sum;i++){
                jcpoint[i] = new Point();
                jcpoint[i].x = sc.nextInt();
                jcpoint[i].y = sc.nextInt();
                jcpoint[i].distancesq = (int) (Math.pow(x-jcpoint[i].x, 2) + Math.pow(y-jcpoint[i].y, 2));
                int temp = jcpoint[i].distancesq;
                if(temp < min1){
                    book[2] = book[1];
                    book[1] = book[0];
                    book[0] = i+1;
                    min3 = min2;
                    min2 = min1;
                    min1 = temp;
                }else if(temp < min2){
                    book[2] = book[1];
                    book[1] = i+1;
                    min3 = min2;
                    min2 = temp;
                }else if(temp < min3){
                    book[2] = i+1;
                    min3 = temp;
                }
            }
            for(int i = 0;i < 3;i++)
                System.out.println(book[i]);
        }
    }
    
  • 相关阅读:
    Sublime安装package control的操作
    Sublime的简单操作
    C# 泛型方法
    C# 数组的讲解(ArrayList 与List的区别)
    免费的天气API
    bootstrapValidator的验证
    sqlServer 多行合并为一行
    bootstrap的安装注意
    SQL数据库中把一个表中的数据复制到另一个表中
    JavaScript的误区
  • 原文地址:https://www.cnblogs.com/jiaohuadehulike/p/14294999.html
Copyright © 2011-2022 走看看