1 import java.util.Scanner;
2
3 //给坐标每个格子都设置为flag为0,画到的格子flag为1,统计1的个数就是被涂上颜色的面积
4
5 public class two {
6
7 public static void main(String[] args) {
8 Scanner scanner = new Scanner(System.in);
9 int n = scanner.nextInt();
10 int[][] flag = new int[200][200];
11 for (int i = 0; i < n; i++) {
12 int x1 = scanner.nextInt();
13 int y1 = scanner.nextInt();
14 int x2 = scanner.nextInt();
15 int y2 = scanner.nextInt();
16 for (int j = x1; j < x2; j++) {
17 for (int k = y1; k < y2; k++) {
18 flag[j][k] = 1;
19 }
20 }
21 }
22 int sum = 0;
23 for (int i = 0; i < 200; i++) {
24 for (int j = 0; j < 200; j++) {
25 if (flag[i][j] == 1) {
26 sum++;
27 }
28 }
29 }
30 System.out.println(sum);
31 }
32
33 }
原文:https://www.cnblogs.com/helloCindy/p/12324152.html