一、题目
AcWing1761. 阻挡广告牌
二、分析
使用一个二维数组标记上广告牌的部位并记录多少格,后面查询卡车挡到的位置并减去该格数。
三、代码
#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
bool st[N][N];
int sum;
int main()
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1 += 1000, y1 += 1000, x2 += 1000 - 1, y2 += 1000 - 1;
for (int i = x1; i <= x2; i++)
{
for (int j = y1; j <= y2; j++)
{
st[i][j] = true;
sum++;
}
}
cin >> x1 >> y1 >> x2 >> y2;
x1 += 1000, y1 += 1000, x2 += 1000 - 1, y2 += 1000 - 1;
for (int i = x1; i <= x2; i++)
{
for (int j = y1; j <= y2; j++)
{
if (!st[i][j])
sum++;
st[i][j] = true;
}
}
cin >> x1 >> y1 >> x2 >> y2;
x1 += 1000, y1 += 1000, x2 += 1000 - 1, y2 += 1000 - 1;
for (int i = x1; i <= x2; i++)
{
for (int j = y1; j <= y2; j++)
{
if (st[i][j])
sum--;
}
}
cout << sum << endl;
return 0;
}
|