全部RE啊啊啊啊啊啊啊啊啊
  • 板块P1141 01迷宫
  • 楼主Gtortoise
  • 当前回复10
  • 已保存回复10
  • 发布时间2021/10/10 19:23
  • 上次更新2023/11/4 04:08:23
查看原帖
全部RE啊啊啊啊啊啊啊啊啊
462158
Gtortoise楼主2021/10/10 19:23
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long color,cnt=0,kkk;

const int Maxn=1010;
int x,y;
bool mp[Maxn][Maxn];
int ans[1000010];
int vis[Maxn][Maxn];

int xx[]={0,1,0,-1};
int yy[]={1,0,-1,0};

void bfs(int x,int y)//搜搜索 
{
	queue<int>h;
	queue<int>l;
	h.push(x);
	l.push(y);
	vis[x][y]=color;
	
	
	while( !h.empty() )
	{
		for(int i=0;i<4;i++)
	    {
			int dx=h.front()+xx[i];
			int dy=l.front()+yy[i];
			if( dx>=1 && dx<=n && dy>=1 && dy<=n&&  !vis[dx][dy]  &&  mp[dx][dy]!=mp[h.front()][l.front()]  )
			{
				h.push(dx);
				l.push(dy);
				vis[dx][dy]=color;
			}
			h.pop();
			l.pop();
			cnt++;
		}
	}
}

int main()
{
//	freopen("aa.in","r"stdin);
//	freopen("aa.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			char x;
			cin>>x;
			if(x=='1')
			{
				mp[i][j]=1;
			}
			else
			{
				mp[i][j]=0;
			}
		}
	}//输入 迷宫 
	
	

	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			//cout<<i<<" "<<j<<endl;
			if(!vis[i][j])
			{
				color++;
				bfs(i,j);
				ans[color]=cnt;
				cnt=0;
			}
		}
	}//搜起来
	
	
	
	
	
	
	
	for(int i=1;i<=m;i++)
	{
		
		cin>>x>>y;
		cout<<ans[vis[x][y]]<<endl;
	}//输出出 
	 
	return 0;
}






怎么办吖,,,球球大佬们惹






2021/10/10 19:23
加载中...