栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

CSP 202009-1 称检测点查询(Java)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CSP 202009-1 称检测点查询(Java)

题目链接:

计算机软件能力认证考试系统http://118.190.20.162/view.page?gpid=T113

【分析】计算距离,然后用一个Pair存储,按照要求排序即可。

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static class Pair{
        int d;
        int i;
        public Pair(int d, int i){
            this.d = d;
            this.i = i;
        }
    }

    static class cmp implements Comparator {
        @Override
        public int compare(Pair o1, Pair o2){
            if(o1.d < o2.d || (o1.d == o2.d && o1.i < o2.i)) return -1;
            return 1;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n, x, y, a, b;
        n = scanner.nextInt();
        x = scanner.nextInt();
        y = scanner.nextInt();
        int i, j;
        List list = new ArrayList<>();
        for(i = 0; i < n; i++){
            a = scanner.nextInt();
            b = scanner.nextInt();
            list.add(new Pair((a - x) * (a - x) + (b - y) * (b - y), i + 1));
        }
        list.sort(new cmp());
//        for(Pair pair: list){
//            System.out.print(pair.i);
//            System.out.print(" ");
//            System.out.print(pair.d);
//            System.out.println();
//        }
        for(i = 0; i < 3; i++){
            System.out.println(list.get(i).i);
        }
    }

}

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/764113.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号