为什么每次都是少1啊……求帮忙
查看原帖
为什么每次都是少1啊……求帮忙
697254
sz2175楼主2022/4/1 14:41

我的1,4,5题总是在第四列(应该是个位吧

代码见下:

#include<bits/stdc++.h>
using namespace std;
int numh,numy,hx,hy,yx,yy,len,i,j,k,l,m,n,square[105][105],dark=0;
int main(){
	cin>> len >> numh >> numy;
	len++;
	for(i=2;i<=len;i++){
		for(j=2;j<=len;j++) square[i][j]=1;
	}
	for(k=1;k<=numh;k++){
		cin>> hx >> hy;
		hx++;
		hy++;
		square[hx][hy]=0;
		square[hx-1][hy]=0;
		square[hx-2][hy]=0;
		square[hx+1][hy]=0;
		square[hx+2][hy]=0;
		square[hx][hy-1]=0;
		square[hx][hy-2]=0;
		square[hx][hy+1]=0;
		square[hx][hy+2]=0;
		square[hx-1][hy-1]=0;
		square[hx-1][hy+1]=0;
		square[hx+1][hy-1]=0;
		square[hx+1][hy+1]=0;
	}
	for(l=1;l<=numy;l++){
		cin>> yx >> yy;
		yx++;
		yy++;
		square[yx-2][yy-2]=0;
		square[yx-2][yy-1]=0;
		square[yx-2][yy]=0;
		square[yx-2][yy+1]=0;
		square[yx-2][yy+2]=0;
		square[yx-1][yy-2]=0;
		square[yx-1][yy-1]=0;
		square[yx-1][yy]=0;
		square[yx-1][yy+1]=0;
		square[yx-1][yy+2]=0;
		square[yx][yy-2]=0;
		square[yx][yy-2]=0;
		square[yx][yy]=0;
		square[yx][yy+1]=0;
		square[yx][yy+2]=0;
		square[yx+1][yy-2]=0;
		square[yx+1][yy-1]=0;
		square[yx+1][yy]=0;
		square[yx+1][yy+1]=0;
		square[yx+1][yy+2]=0;
		square[yx+2][yy-2]=0;
		square[yx+2][yy-1]=0;
		square[yx+2][yy]=0;
		square[yx+2][yy+1]=0;
		square[yx+2][yy+2]=0;
	}
	for(m=2;m<=len;m++){
		for(n=2;n<=len;n++) {
			dark+=square[m][n];
		}
	}
	cout<< dark;
	return 0; 
}

(对不起我是蒟蒻,只会枚举算法啊,什么函数都不太会呢……)

2022/4/1 14:41
加载中...