题目链接:https://www.luogu.com.cn/problem/P1789
My Answer Code:
/*
Author:Albert Tesla Wizard
Time:2021/2/28 0:50
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m,k;
cin>>n>>m>>k;
int a[n+1][n+1];
memset(a,0,sizeof(a));
int b[m+1][2];
int c[k+1][2];
for(int i=1;i<=m;i++)
for(int j=0;j<2;j++)cin>>b[i][j];
for(int i=1;i<=k;i++)
for(int j=0;j<2;j++)cin>>c[i][j];
for(int i=1;i<=m;i++)
{
int x=b[i][0],y=b[i][1];
a[x][y]=1;
if(x>=3){a[x-1][y]=1;a[x-2][y]=1;}
else if(x==2)a[x-1][y]=1;
if(x<=n-2){a[x+1][y]=1;a[x+2][y]=1;}
else if(x==n-1)a[x+1][y]=1;
if(y>=3){a[x][y-1]=1;a[x][y-2]=1;}
else if(y==2)a[x][y-1]=1;
if(y<=n-2){a[x][y+1]=1;a[x][y+2]=1;}
else if(y==n-1)a[x][y+1]=1;
if(x>=2&&y>=2)a[x-1][y-1]=1;
if(x>=2&&y<=n-1)a[x-1][y+1]=1;
if(x<=n-1&&y<=n-1)a[x+1][y+1]=1;
if(x<=n-1&&y>=2)a[x+1][y-1]=1;
}
for(int i=1;i<=k;i++)
{
int x=c[i][0],y=c[i][1];
a[x][y]=1;
int x1,x2,y1,y2;
if(x>=3)x1=x-2;
else x1=1;
if(x<=n-2)x2=x+2;
else x2=n;
if(y>=3)y1=y-2;
else y1=1;
if(y<=n-2)y2=y+2;
else y2=n;
for(int f=x1;f<=x2;f++)
for(int e=y1;e<=y2;e++)a[f][e]=1;
}
int ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(!a[i][j])ans++;
}
cout<<ans<<'\n';
return 0;
}