首先,我们可以先用数组来储存地图(建议用int,我试过bool会RE)
每次读入火把和萤石的坐标
接着把能照亮的地方标记起来
最后用计数器统计会生成怪的地方有钻石的话还怕怪吗
最后,上代码
#include<stdio.h>
int main()
{
int a[1010][1010],n,m,k, i, j,x,y,z,g=0;
scanf("%d%d%d", &n, &m, &k);
for ( i = 1; i <=n; i++)
{
for (j = 1; j <=n; j++)
a[i][j] = 0;
}
for ( i = 0; i < m; i++)
{
scanf("%d%d", &x, &y);
a[x - 2][y] = a[x - 1][y + 1] = a[x - 1][y] = a[x - 1][y - 1] = a[x][y + 2] = a[x][y + 1] = a[x][y] = a[x][y - 1] = a[x][y - 2] = a[x + 1][y + 1] = a[x + 1][y] = a[x + 1][y - 1] = a[x + 2][y] = 1;
}
for (i = 0; i < k; i++)
{
scanf("%d%d", &x, &y);
for ( j = -2; j <= 2; j++)
{
for (z =-2 ; z <=2; z++)
a[x+j][y+z] = 1;
}
}
for ( i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (a[i][j] == 0)
g++;
}
}
printf("%d", g);
return 0;
}
?