CCF计算机软件能力认证202009前两题java满分解

第一题

package ccf202009;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class p1 {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = bf.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int X = Integer.parseInt(temp[1]);
        int Y = Integer.parseInt(temp[2]);
        int[] x = new int[n + 1];
        int[] y = new int[n + 1];
        double[][] list = new double[n + 1][2];

        for (int i = 1; i <= n; i++) {
            temp = bf.readLine().split(" ");
            x[i] = Integer.parseInt(temp[0]);
            y[i] = Integer.parseInt(temp[1]);
            double res = Math.sqrt((X - x[i]) * (X - x[i]) + (Y - y[i]) * (Y - y[i]));
            list[i][0] = i;
            list[i][1] = res;
        }
        getSort(list, n);
        String res = "%.0f %n";
        for (int i = 1; i < 4; i++) {
            System.out.printf(res, list[i][0]);
        }
    }

    public static void getSort(double[][] list, int n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n - i; j++) {
                if (list[j][1] > list[j + 1][1]) {
                    double d0 = list[j][0];
                    list[j][0] = list[j + 1][0];
                    list[j + 1][0] = d0;
                    double d1 = list[j][1];
                    list[j][1] = list[j + 1][1];
                    list[j + 1][1] = d1;
                }
            }
        }
    }
}

第二题

package ccf202009;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class p2 {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = bf.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        int t = Integer.parseInt(temp[2]);
        int xl = Integer.parseInt(temp[3]);
        int yd = Integer.parseInt(temp[4]);
        int xr = Integer.parseInt(temp[5]);
        int yu = Integer.parseInt(temp[6]);
        long[][] xy = new long[n][2 * t];
        for (int i = 0; i < n; i++) {
            temp = bf.readLine().split(" ");
            for (int j = 0; j < 2 * t; j += 2) {
                xy[i][j] = Integer.parseInt(temp[j]);
                xy[i][j + 1] = Integer.parseInt(temp[j + 1]);
            }
        }
        int arrive = 0;
        int stop = 0;
        for (int i = 0; i < n; i++) {
            int count = 0;
            int flag = 0;
            for (int j = 0; j < 2 * t; j += 2) {
                long x = xy[i][j];
                long y = xy[i][j + 1];
                if ((x >= xl && x <= xr) && (y >= yd && y <= yu)) {
                    count++;
                    if (j > 0) {
                        if ((xy[i][j - 2] >= xl && xy[i][j - 2] <= xr) && (xy[i][j - 1] >= yd && xy[i][j - 1] <= yu)) {
                            flag++;
                        } else {
                            flag = 0;
                        }
                        if (flag >= k - 1) {
                            stop++;
                            break;
                        }
                    }
                }
            }
            if (count > 0) {
                arrive++;
            }
        }
        System.out.println(arrive);
        System.out.println(stop);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值