题目链接: oj
解题思路
- 注意到全部数据中,L非常大,所以不能把绿化图直接存成矩阵。因为藏宝图左下角一定是1,所以我们可以把树的位置存在数组中,再遍历数组进行检验。
- 绿化图最右上角有一些元素因为剩余空间不够,所以必然不可能够成藏宝图的样子。
- 可以用class代替struct来实现运算符重载。
AC代码
/*
ccfcsp认证的第二题近几次难度有所增加,不再是简单模拟就可以得满分。
简单模拟会因为超时或者超空间等限制最多只能拿70分。
另外30分,限制难度也是越来越大。
比较青睐的考点:差分+前缀和 、 二维前缀和。
*/
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;
class point
{
public:
int x, y;
bool operator==(point a)
{
return this->x == a.x && this->y == a.y;
}
};
vector<point> v, cbt;
int main()
{
int n, l, s;
scanf("%d%d%d", &n, &l, &s);
for (int i = 0; i < n; i++)
{
point buf;
scanf("%d%d", &buf.x, &buf.y);
v.push_back(buf);
}
int array[s + 1][s + 1];
for (int i = s; i >= 0; i--)
{
for (int j = 0; j <= s; j++)
scanf("%d", &array[i][j]);
}
int count = 0;
for (vector<point>::const_iterator a = v.begin(); a != v.end(); a++)
{
point buf = *a;
int flag = 1;
for (int i = 0; i <= s; i++)
{
for (int j = 0; j <= s; j++)
{
point b;
b.x = buf.x + i;
b.y = buf.y + j;
vector<point>::const_iterator it = find(v.begin(), v.end(), b);
if ((array[i][j] == 1 && it == v.end()) || (array[i][j] == 0 && it != v.end())||b.x>l||b.y>l)
{
flag = 0;
i = s;
j = s;
}
}
}
if (flag)
{
count++;
}
}
printf("%d", count);
return 0;
}