牛客_浇花

浇花
https://www.nowcoder.com/practice/1eaabd93f16946f28c5917b3e9d9df48

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            solution(in);
        }
    }

    /**
     * 排序: 贪心
     * @param in
     */
    private static void solution(Scanner in){
        int n = in.nextInt();
        int x1 = in.nextInt();
        int y1 = in.nextInt();
        int x2 = in.nextInt();
        int y2 = in.nextInt();

        long[][] dist = new long[n][2];

        long x,y;
        for(int i=0; i<n; i++){
            x = in.nextInt();
            y = in.nextInt();
            dist[i][0] = (x1-x)*(x1-x) + (y1-y)*(y1-y);
            dist[i][1] = (x2-x)*(x2-x) + (y2-y)*(y2-y);
        }

        // 到喷泉(x1,y1)距离降序
//            Arrays.sort(dist, (o1, o2) -> o2[0]>o1[0]?1:-1);
        Arrays.sort(dist, (o1, o2) -> Long.compare(o2[0], o1[0]));

        long squareR1 = 0;
        long squareR2 = 0;
        long result = Long.MAX_VALUE;
        for(int i=0; i<n; i++){
            squareR1 = dist[i][0];
            result = Math.min(result, squareR1+squareR2);
            squareR2 = Math.max(squareR2, dist[i][1]);
        }
        // 全部花由 喷泉(x2,y2)浇水
        result = Math.min(result, 0+squareR2);

        System.out.println(result);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值