AcWing 蓝桥杯 3536. 矩形的总面积
原题链接
简单
作者:
JustDoIt11
,
2024-04-09 21:18:03
,
所有人可见
,
阅读 5
import java.io.*;
import java.util.StringTokenizer;
public class Main {
static Read sc = new Read();
static BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out));
// 使用快读一定注意是否 + "\n" 和 关流close
// 不管啥时候, 直接用long就行了
public static void main(String[] args) throws IOException {
int x1 = sc.nextInt(), y1 = sc.nextInt();
int x2 = sc.nextInt(), y2 = sc.nextInt();
int x3 = sc.nextInt(), y3 = sc.nextInt();
int x4 = sc.nextInt(), y4 = sc.nextInt();
int lpx, lpy, rpx, rpy;
rpx = Math.min(x2, x4);
rpy = Math.min(y2, y4);
lpx = Math.max(x1, x3);
lpy = Math.max(y1, y3);
long overlap = 0;
if (rpx >= lpx && rpy >= lpy) overlap = (long) (rpx - lpx) * (rpy - lpy);
long area2 = (long) (x4 - x3) * (y4 - y3);
long area1 = (long) (x2 - x1) * (y2 - y1);
bufferedWriter.write((area2 + area1 - overlap) + "\n");
bufferedWriter.close();
}
private static class Read { // 快读
StringTokenizer st = new StringTokenizer("");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return bf.readLine();
}
}
}