试题编号: | 202303-1 |
试题名称: | 田地丈量 |
时间限制: | 1.0s |
内存限制: | 512.0MB |
问题描述: | 问题描述西西艾弗岛上散落着 𝑛 块田地。每块田地可视为平面直角坐标系下的一块矩形区域,由左下角坐标 (𝑥1,𝑦1) 和右上角坐标 (𝑥2,𝑦2) 唯一确定,且满足 𝑥1<𝑥2、𝑦1<𝑦2。这 𝑛 块田地中,任意两块的交集面积均为 0,仅边界处可能有所重叠。 最近,顿顿想要在南山脚下开垦出一块面积为 𝑎×𝑏 矩形田地,其左下角坐标为 (0,0)、右上角坐标为 (𝑎,𝑏)。试计算顿顿选定区域内已经存在的田地面积。 输入格式从标准输入读入数据。 输入共 𝑛+1 行。 输入的第一行包含空格分隔的三个正整数 𝑛、𝑎 和 𝑏,分别表示西西艾弗岛上田地块数和顿顿选定区域的右上角坐标。 接下来 𝑛 行,每行包含空格分隔的四个整数 𝑥1、𝑦1、𝑥2 和 𝑦2,表示一块田地的位置。 输出格式输出到标准输出。 输出一个整数,表示顿顿选定区域内的田地面积。 样例输入 样例输出 子任务全部的测试数据满足 𝑛≤100,且所有输入坐标的绝对值均不超过 104。 |
import java.io.*;
public class Main {
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
static QuickInput in = new QuickInput();
public static int jiao(int x1,int x2,int y1,int y2){
int tou=Math.max(x1,y1);
int wei=Math.min(x2,y2);
if(tou<wei){
return wei-tou;
}
return 0;
}
public static int get(int i,int[][] arr,int a,int b){
int c=jiao(arr[i][0],arr[i][2],0,a);
int k=jiao(arr[i][1],arr[i][3],0,b);
return c*k;
}
public static void main(String[] args) throws IOException {
int n = in.nextInt();
int a=in.nextInt();
int b=in.nextInt();
int[][] arr=new int[n][4];
int sum=0;
for(int i=0;i<n;i++){
arr[i][0]=in.nextInt();
arr[i][1]=in.nextInt();
arr[i][2]=in.nextInt();
arr[i][3]=in.nextInt();
sum+=get(i,arr,a,b);
}
out.println(sum);
out.flush();
}
static class QuickInput {
StreamTokenizer input = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int nextInt() throws IOException {
input.nextToken();
return (int) input.nval;
}
}
}