ABC311 D
  • 板块灌水区
  • 楼主code_hyx
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/7/22 21:42
  • 上次更新2023/11/3 08:10:47
查看原帖
ABC311 D
530797
code_hyx楼主2023/7/22 21:42

为什么不对啊啊啊啊啊啊啊!第二个样例都过了

#include<bits/stdc++.h>
using namespace std;
int n,m,vis[205][205],cnt=0;
char ch[205][205];
void dfs(int x,int y,int xx,int yy)
{
	//cout<<x<<" "<<y<<"\n";
	if(x<1||x>n||y<1||y>m)return;
	if(vis[x][y]>10)return;
	if(ch[x][y]=='#')
	{
		x-=xx;
		y-=yy;
		if(xx!=0&&yy!=1&&ch[x][y+1]=='.')dfs(x,y+1,0,1);
		if(xx!=0&&yy!=-1&&ch[x][y-1]=='.')dfs(x,y,0,-1);
		if(xx!=1&&yy!=0&&ch[x+1][y]=='.')dfs(x+1,y,1,0);
		if(xx!=-1&&yy!=0&&ch[x-1][y]=='.')dfs(x-1,y,-1,0);
	}
	else
	{
		vis[x][y]++;
		dfs(x+xx,y+yy,xx,yy);
	} 
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>ch[i][j];
		}
	}
	dfs(2,2,0,1);
	dfs(2,2,0,-1);
	dfs(2,2,1,0);
	dfs(2,2,-1,0);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(vis[i][j]>0)
			{
				//cout<<i<<" "<<j<<"\n";
				cnt++;
			}
		}
	}
	cout<<cnt;
	return 0;
}
2023/7/22 21:42
加载中...