转换把面积用经过的点来表示,用一个二维数组来存储经过的点的为大于0,最后循环遍历点数大于0的数和就是面积
import java.util.Scanner;
public class Drawing {
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] area = new int[101][101];// 面积经过的点
for (int i = 0; i < n; i++) {
int x1 = scanner.nextInt();
int x2 = scanner.nextInt();
int y1 = scanner.nextInt();
int y2 = scanner.nextInt();
for (int j = x1 + 1; j <= y1; j++)
for (int k = x2 + 1; k <= y2; k++)
area[j][k]++;
}
int count = 0;
for (int i = 0; i < 101; i++)
for (int j = 0; j < 101; j++)
if (area[i][j] > 0)
count++;
System.out.println(count);
scanner.close();
}
}