20求助
查看原帖
20求助
492010
RAVE_LOVEo_O楼主2022/9/24 12:30

为什么20分

WA了

#include<bits/stdc++.h>
using namespace std;
int n,i,a[105][105],s,j;
char b;
int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+(ch-'0');
		ch=getchar();
	}
	return x*f;
}
void write(int x) {
	if(x<0){
		putchar('-');
		write(-x);
		return;
	}
	if(x>=10)write(x/10);
	putchar(x%10+'0');
}
int dfs(int x,int y)
{
	int i,j,s=0;
	for(i=1;i<=n;i++)
	{
        if(x-i<1)break;
        if(y-i<1)break;
        if(x+i>n)break;
        if(y+i>n)break;
		if(a[x-i][y-i]&&a[x-i][y+i]&&a[x+i][y-i]&&a[x+i][y+i])s++;
        if(x-i-1<1)break;
        if(y-i-1<1)break;
        if(x+i+1>n)break;
        if(y+i+1>n)break;
		if(a[x-i][y-i]&&a[x][y+1]&&a[x+1][y]&&a[x+1][y+1]&&a[x-i][y+i+1]&&a[x+i+1][y-i]&&a[x+i+1][y+i+1])s++;
	}
	return s;
}
int main()
{
	n=read();
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			cin>>b;
			a[i][j]=(b-'0');
		}
	}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			if(a[i][j]){
				s+=dfs(i,j);
				if(a[i][j+1]&&a[i+1][j]&&a[i+1][j+1])s++;
			}
	write(s);
	return 0;
}
2022/9/24 12:30
加载中...