20分求解,哪里错了呢,希望大佬指教
查看原帖
20分求解,哪里错了呢,希望大佬指教
592681
ran_Diana楼主2022/9/24 16:38
#include<bits/stdc++.h>
using namespace std;
long long n,a[1000][1000],ans,num,sum;
string s[1000];
int read()
{
	int x=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*w;
}
int dfs1(long long x,long long y,long long dep)
{
	if(s[x-dep][y-dep]=='1'&&s[x+dep][y-dep]=='1'&&s[x-dep][y+dep]=='1'&&s[x+dep][y+dep]=='1')
	{
		ans++;
		dfs1(x,y,dep+1);
	}
	return ans;
}
int dfs2(long long x,long long y,long long dep)
{
	if(x-dep<1||y-dep<0||x+1+dep>n||y+1+dep>=n)
	return ans;
	if(dep==0)
	if(s[x+1][y]=='1'&&s[x][y]=='1'&&s[x][y+1]=='1'&&s[x+1][y+1]=='1')
	{
		ans++;num++;
		dfs2(x,y,dep+1);
	}
	else
	if(s[x-dep][y-dep]=='1'&&s[x+dep+1][y-dep]=='1'&&s[x+1+dep][y+1+dep]=='1'&&s[x-dep][y+1+dep]=='1')
	{
		ans++;sum++;
		dfs2(x,y,dep+1);
	}
	return ans;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		cin>>s[i];
	for(int i=1;i<=n;i++)
		for(int j=0;j<n;j++)
		{
			if(s[i][j]=='1')
			{
				dfs1(i,j,1);
				dfs2(i,j,0);	
			}
		}
		printf("%lld",ans);
	return 0;
}

2022/9/24 16:38
加载中...