-
问题链接:画图
-
问题分析:模拟法解决。
-
程序说明:n表示矩形个数;map数组记录坐标轴情况,此单位为true,则计算面积。
-
程序代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Reader {
static StringTokenizer token =new StringTokenizer("");
static BufferedReader reader =new BufferedReader (new InputStreamReader(System.in)) ;
static String nextLine() throws IOException {
return reader.readLine() ;
}
static String next() throws IOException {
while(!token.hasMoreTokens()) {
token =new StringTokenizer(reader.readLine()) ;
}
return token.nextToken() ;
}
static int nextInt() throws IOException {
return Integer.parseInt(next()) ;
}
static double nextDouble() throws IOException {
return Double.parseDouble(next()) ;
}
}
public class Main {
public static void main(String[] args) throws IOException {
int n = Reader.nextInt();
boolean[][] map = new boolean[100][100];//false
int res=0;
for(int i=0;i<n;i++) {
int x1=Reader.nextInt();
int y1=Reader.nextInt();
int x2=Reader.nextInt();
int y2=Reader.nextInt();
for(int p=y1;p<y2;p++) {
for(int q=x1;q<x2;q++) {//借鉴物理中时间轴和时间的概念,0即表示0-1这里单位面积
if(map[p][q]!=true) {
map[p][q]=true;
res++;
}
}
}
}
System.out.print(res);
}
}