memset
包含在cstring
头文件中,否者编译错误
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 100;
bool flag[N + 10][N + 10];
struct Rectangle {
int x1, y1, x2, y2;
int getNum() {
return (x2 - x1) * (y2 - y1);
}
} r[N + 10];
int main() {
int n;
cin >> n;
int cnt = 0;
memset(flag, false, sizeof(flag));
for (int i = 0; i < n; ++i) {
cin >> r[i].x1 >> r[i].y1 >> r[i].x2 >> r[i].y2;
cnt += r[i].getNum();
for (int j = r[i].x1 + 1; j <= r[i].x2; ++j) {
for (int k = r[i].y1 + 1; k <= r[i].y2; ++k) {
if (flag[j][k]) {
--cnt;
} else {
flag[j][k] = true;
}
}
}
}
cout << cnt;
return 0;
}