wa第2个点,我的代码是:
#include<cstdio>
#include<cstring>
using namespace std;
void zhaoliang(int,int,bool);
int n,m,k,hx,hy,ans=0;
bool a[150][150];
int main(){
scanf("%d%d%d",&n,&m,&k);
memset(a,0,sizeof(a));
while(m--){
scanf("%d%d",&hx,&hy);
zhaoliang(hx,hy,0);//0是火把,1是萤石
}
while(k--){
scanf("%d%d",&hx,&hy);
zhaoliang(hx,hy,1);
}
//检查
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(a[i][j]==0){
ans++;
}
}
}
printf("%d",ans);
return 0;
}
void zhaoliang(int x,int y,bool isyingshi){
/*int dx[13]={-2,-1,0,0,0,0,0,1,2,-1,1,-1,1};
int dy[13]={0,0,-2,-1,0,1,2,0,0,-1,-1,1,1};*/
int dx[13]={2,0,-2,0,1,1,1,0,0,0,-1,-1,-1};//火把的x和y
int dy[13]={0,2,0,-2,0,1,-1,1,0,-1,0,1,-1};
int dx2[25]={-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2};//萤石的
int dy2[25]={-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2};
for(int i=0;i<13;i++){
int tx=x+dx[i],ty=y+dy[i];
if(tx<0||tx>=n||ty<0||ty>=n) continue;//越界判断
a[tx][ty]=1;
}
if(isyingshi){
/*int dx2[25]={-2,-2,-2,-2,-1,-1,-1,-1,1,1,1,1,2,2,2,2};
int dy2[25]={-2,-1,1,2,-2,-1,1,2,-2,-1,1,2,-2,-1,1,2};*/
/*int dx2[25]={-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2},//萤石
int dy2[25]={-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2};*/
for(int i=0;i<25;i++){
int tx=x+dx2[i],ty=y+dy2[i];
if(tx<0||tx>=n||ty<0||ty>=n) continue;
a[tx][ty]=1;
}
}
}