思路
这道题并不算难,只需要枚举藏宝图的左下角即可。
我们只需要枚举有树的地方,即枚举 次,每次枚举整个藏宝图判断,总时间复杂度 ,可以 AC。
代码解释:矩阵 太大了存不下,这里我们使用 map 存储该矩阵,定义一个结构体 point 表示点的坐标(虽然其实可以用 pair),定义一个数组 t 存储有树的点。
AC CODE
#include<cstdio>
#include<map>
struct point
{
int x,y;
bool operator<(const point& a) const
{
if(x!=a.x)return x<a.x;
return y<a.y;
}
}t[1001];
bool S[51][51];
std::map<point,bool>p;
int main()
{
int n,l,s;
scanf("%d%d%d",&n,&l,&s);
for(int i=1;i<=n;i++)scanf("%d%d",&t[i].x,&t[i].y),p[t[i]]=true;
for(int i=0,a;i<=s;i++)
{
for(int j=0;j<=s;j++)
{
scanf("%d",&a);
S[s-i][j]=a;
}
}
int ans=0;
for(int i=1;i<=n;i++)
{
int x=t[i].x,y=t[i].y;
bool pd=true;
for(int nx=x;nx<=x+s&&pd;nx++)
{
for(int ny=y;ny<=y+s&&pd;ny++)
{
point now;
now.x=nx;
now.y=ny;
if(nx>l||ny>l||S[nx-x][ny-y]!=p[now])
{
ans--;
pd=false;
}
}
}
ans++;
}
printf("%d",ans);
}