样例没过
查看原帖
样例没过
494992
underline__jian楼主2022/9/24 22:43
#include<iostream>
#include<algorithm>
#define re register

using namespace std;
int n,cnt_1,cnt_2;
char str[1010][1010]; 
int main(){
	scanf("%d",&n);
	for(re int i=1;i<=n;i++) 
		for(re int j=1;j<=n;j++) cin>>str[i][j];
	for(re int i=1;i<=n;i++)
		for(re int j=1;j<=n;j++)
			if(str[i][j]=='1'){
				if(str[i-1][j-1]=='1'&&str[i-1][j+1]=='1'&&str[i+1][j-1]=='1'&&str[i+1][j+1]=='1') cnt_1++;
				else break; //不能用continue 
			}
	/*
	判定种类一:长度为奇数的'X'连通块;
	1 0 0 0 1
	0 1 0 1 0
	0 0 1 0 0
	0 1 0 1 0
	1 0 0 0 1 
	具体思路:
	首先找中心 str[i][j]
	以中心向四周扩散判定四个角是否为"1"
	*/
	for(re int i=1;i<=n;i++)
		for(re int j=1;j<=n;j++)
			if(str[i][j]=='1'&&str[i+1][j]=='1'&&str[i][j+1]=='1'&&str[i+1][j+1]=='1'){
				if(str[i-1][j-1]=='1'&&str[i+2][j-1]=='1'&&str[i-1][j+2]=='1'&&str[i+2][j+2]=='1') cnt_2++;
				else break;
			}
	/*
	判定种类二:
	0 0 0 0
	0 1 1 0
	0 1 1 0
	0 0 0 0
	思路:找由1组成的正方体,然后同上,向四周扩散
	问题应该在找正方体 
	*/
	printf("%d",cnt_1+cnt_2);
	return 0;
}
2022/9/24 22:43
加载中...