欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

洛谷P5831题题解(Java语言描述)

程序员文章站 2022-07-13 13:36:13
...

题目要求

P5831题目链接

洛谷P5831题题解(Java语言描述)
洛谷P5831题题解(Java语言描述)

AC代码(Java语言描述)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int line = scanner.nextInt(), num = scanner.nextInt(), counter = 0;
        int[] array = new int[21];
        boolean book[][] = new boolean[21][21];
        for (int p = line; p > 0; p--) {
            for(int i = 1; i <= num; i++) {
                array[i] = scanner.nextInt();
            }
            for(int i = 1; i <= num; i++) {
                book[array[i]][array[i]] = true;
            }
            for(int i = 1; i <= num; i++) {
                for(int j = i+1; j <= num; j++) {
                    book[array[j]][array[i]] = true;
                }
            }
        }
        for(int i = 1; i <= num; i++) {
            for(int j = 1; j <= num; j++) {
                if(!book[i][j]) {
                    counter++;
                }
            }
        }
        System.out.println(counter);
        scanner.close();
    }
}
相关标签: # 菜鸡逛洛谷