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

第一题

package ccf201401;

import java.util.Scanner;

public class p1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int count = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
            for (int j = 0; j < i; j++) {
                if (s[j] == (s[i] * (-1))) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}

第二题

package ccf201401;

import java.util.Scanner;

public class p2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] xy = new int[n + 1][5];
        for (int i = 1; i < n + 1; i++) {
            for (int j = 0; j < 4; j++) {
                xy[i][j] = sc.nextInt();
            }
            xy[i][4] = i;
        }
        int[][] pq = new int[m + 1][2];
        for (int i = 1; i < m + 1; i++) {
            for (int j = 0; j < 2; j++) {
                pq[i][j] = sc.nextInt();
            }
        }
        Select(n, m, xy, pq);
    }

    public static void Swap(int n, int[][] xy, int k) {
        int max = xy[1][4];
        System.out.println(k);
        for (int i = 1; i < n + 1; i++) {
            if (xy[i][4] > max) {
                max = xy[i][4];
            }
        }
        xy[k][4] = max + 1;
    }

    public static void Select(int n, int m, int[][] xy, int[][] pq) {
        for (int i = 1; i < m + 1; i++) {
            int res = 0;
            for (int k = 1; k < n + 1; k++) {
                if (pq[i][0] >= xy[k][0] && pq[i][0] <= xy[k][2] && pq[i][1] >= xy[k][1] && pq[i][1] <= xy[k][3]) {
                    if (xy[res][4] < xy[k][4]) {
                        res = k;
                    }
                }
            }
            if (res > 0) {
                Swap(n, xy, res);
            } else {
                System.out.println("IGNORED");
            }
        }
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值