const fs = require("fs");
const input = fs.readFileSync(0).toString().trim().split('\n');
// Please Write your code here.
const [ax1, ay1, ax2, ay2] = input[0].split(" ").map(Number);
const [bx1, by1, bx2, by2] = input[1].split(" ").map(Number);
function getResult() {
const areaA = (ax2 - ax1) * (ay2 - ay1);
if (bx1 <= ax1 && by1 <= ay1 && bx2 >= ax2 && by2 >= ay2) return 0;
const ix1 = Math.max(ax1, bx1);
const iy1 = Math.max(ay1, by1);
const ix2 = Math.min(ax2, bx2);
const iy2 = Math.min(ay2, by2);
if (ix1 >= ix2 || iy1 >= iy2) return areaA;
if (iy1 === ay1 && iy2 === ay2) {
if (ix1 === ax1) return (ax2 - ix2) * (ay2 - ay1);
if (ix2 === ax2) return (ix1 - ax1) * (ay2 - ay1);
return areaA;
}
if (ix1 === ax1 && ix2 === ax2) {
if (iy1 === ay1) return (ax2 - ax1) * (ay2 - iy2);
if (iy2 === ay2) return (ax2 - ax1) * (iy1 - ay1);
return areaA;
}
return areaA;
}
console.log(getResult());
const ix1 = Math.max(ax1, bx1);
const iy1 = Math.max(ay1, by1);
const ix2 = Math.min(ax2, bx2);
const iy2 = Math.min(ay2, by2);
y ^
|
| B
| +---------+
| | |
| | +-----+----+
| | | I | | A
| | +-----+----+
| | |
| +---------+
|
+------------------------> x
y ^
|
| A B
| +-----+ +-----+
| | | | |
| +-----+ +-----+
|
+------------------------> x
y ^
|
| B
| +---------+
| | A |
| | +-----+ |
| | | | |
| | +-----+ |
| +---------+
|
+------------------------> x
링크
풀이
풀이 확인하기 (클릭)
1. 접근 방식 (논리적 흐름)
2. 해결 코드 (또는 Pseudocode)
잘한 사람 코드 (클릭)
1. 풀이
2. 아이디어 해석
[전반적인 아이디어]
[교차 영역에 대한 아이디어]