用暴力枚举做的。
每一个格子遍历,没有访问过就寻找它所能到达的点,标记、计数,再从这些格子寻找......直到所有的格子均被访问过。统计数量
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int dx[10]={0,3,3,1,1,-3,-3,-1,-1};
int dy[10]={0,1,-1,3,-3,1,-1,3,-3};
struct node
{
int x,y,dep;
}list[2100];
int n,m,k,ans=0;
int p,t,head,tail;
bool v[210][210];
void bfs(int stx,int sty)
{
p=1;t=0;
head=1,tail=2;
list[head].x=stx;list[head].y=sty,list[head].dep=1;
while(head<tail)
{
int x=list[head].x,y=list[head].y,dep=list[head].dep;
for(int i=0 ; i<=9 ; i++)
{
int xx=x+dx[i],yy=y+dy[i];
if(xx>=1 && xx<=n && yy>=1 && yy<=m && v[xx][yy]==true)
{
v[xx][yy]=false;
if(dep%2==0)t++;
else p++;
list[tail].x=xx,list[tail].y=yy,list[tail].dep=dep+1;
tail++;
}
}
head++;
}
ans+=max(p,t);
}
int main()
{
memset(v,true,sizeof(v));
scanf("%d %d %d",&n,&m,&k);
for(int i=1 ; i<=k ; i++)
{
int x,y;
scanf("%d %d",&x,&y);
v[x][y]=false;
}
for(int i=1 ; i<=n ; i++)
{
for(int j=1 ; j<=m ; j++)
{
if(v[i][j]==true)
{
v[i][j]=false;
bfs(i,j);
}
}
}
printf("%d\n",ans);
return 0;
}
真就不知道错哪了