201409-2 画图 Java

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean [][] flag = new boolean[105][105];
        int count = 0;
        for(int i=0;i<n;i++) {
            int x1 = sc.nextInt();
            int y1 = sc.nextInt();
            int x2 = sc.nextInt();
            int y2 = sc.nextInt();
            //矩形全部涂色
            for(int j=y1;j<y2;j++) {
                for(int k=x1;k<x2;k++) {
                    flag[j][k] = true;
                }
            }
        }
        for(int i=0;i<flag.length;i++) {//遍历全部行数
            for(int j=0;j<flag[i].length;j++) {//遍历全部列数
                if(flag[i][j]) {//只会算一次
                    count++;
                }
            }
        }
        sc.close();
        System.out.println(count);
    }

}

猜你喜欢

转载自www.cnblogs.com/yu-jiawei/p/12343195.html
今日推荐