#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,k,n1=0;
cin>>n>>m>>k;
int a[n+5][n+5],x1,y1,x2,y2;
memset(a,0,sizeof(a));
for(int i=1;i<=m;i++){
cin>>x1>>y1;
a[x1][y1]=1;
a[x1-2][y1]=1;
a[x1-1][y1-1]=1;
a[x1-1][y1]=1;
a[x1-1][y1+1]=1;
a[x1+1][y1-1]=1;
a[x1+1][y1]=1;
a[x1+1][y1+1]=1;
a[x1+2][y1]=1;
a[x1][y1-2]=1;
a[x1][y1-1]=1;
a[x1][y1+1]=1;
a[x1][y1+2]=1;
}
if(k!=0){
for(int i=1;i<=k;i++){
cin>>x2>>y2;
a[x2][y2]=1;
a[x2-2][y2-2]=1;
a[x2-2][y2-1]=1;
a[x2-2][y2]=1;
a[x2-2][y2+1]=1;
a[x2-2][y2+2]=1;
a[x2-1][y2-2]=1;
a[x2-1][y2-1]=1;
a[x2-1][y2]=1;
a[x2-1][y2+1]=1;
a[x2-1][y2+2]=1;
a[x2][y2-2]=1;
a[x2][y2-1]=1;
a[x2][y2+1]=1;
a[x2][y2+2]=1;
a[x2+1][y2-2]=1;
a[x2+1][y2-1]=1;
a[x2+1][y2]=1;
a[x2+1][y2+1]=1;
a[x2+1][y2+2]=1;
a[x2+2][y2-2]=1;
a[x2+2][y2-1]=1;
a[x2+2][y2]=1;
a[x2+2][y2+1]=1;
a[x2+2][y2+2]=1;
}
}
for(int i=1;i<=n;i++){
for(int j=1;i<=n;j++){
if(a[i][j]==0)
n1++;
}
}
cout<<n1;
return 0;
}
以上是我的代码。 以下是题解灰名角边边证全等的代码,发现和我很像。
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>//写这么多头文件确实没必要
using namespace std;
int main(){
int n,m,k,i,j,o,p,q,s,ans=0;
cin>>n>>m>>k;
int map[n+5][n+5];
memset(map,0,sizeof(map));
for(i=1;i<=m;i++){
cin>>o>>p;
map[o+2][p]=1;//一个一个找,一个一个亮,暴力时,一定要有顺序,
map[o][p+2]=1;
map[o-2][p]=1;
map[o][p-2]=1;
map[o+1][p]=1;
map[o+1][p+1]=1;
map[o+1][p-1]=1;
map[o][p+1]=1;
map[o][p]=1;
map[o][p-1]=1;
map[o-1][p]=1;
map[o-1][p+1]=1;
map[o-1][p-1]=1;
}
for(i=1;i<=k;i++){
cin>>q>>s;
map[q-2][s-2]=1;
map[q-2][s-1]=1;
map[q-2][s]=1;
map[q-2][s+1]=1;
map[q-2][s+2]=1;
map[q-1][s-2]=1;
map[q-1][s-1]=1;
map[q-1][s]=1;
map[q-1][s+1]=1;
map[q-1][s+2]=1;
map[q][s-2]=1;
map[q][s-1]=1;
map[q][s]=1;
map[q][s+1]=1;
map[q][s+2]=1;
map[q+1][s-2]=1;
map[q+1][s-1]=1;
map[q+1][s]=1;
map[q+1][s+1]=1;
map[q+1][s+2]=1;
map[q+2][s-2]=1;
map[q+2][s-1]=1;
map[q+2][s]=1;
map[q+2][s+1]=1;
map[q+2][s+2]=1;
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(map[i][j]==0)ans++;
}
}
cout<<ans;//搞定
return 0;
}
不是,为什么它可以运行而我的代码只能返回值错误啊,www求助