DFS 0tps求助!
  • 板块P1141 01迷宫
  • 楼主3_14
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/3 15:35
  • 上次更新2025/1/3 15:39:00
查看原帖
DFS 0tps求助!
913288
3_14楼主2025/1/3 15:35
#include<bits/stdc++.h>
#define Freopen(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
#define lcm(x,y) x/__gcd(x,y)*y;
#define lb(x) (x&-x)
#define lf(x) x==0?1:0
#define str to_string
#define Made return
#define by 0
#define _3_14 ;
using namespace std;
const int MAX=1e3+1;
const double EPS=1e-6;
int n,t,mp[MAX][MAX],fx[4][2]={1,0,0,1,-1,0,0,-1},ans=0;
bool book[MAX][MAX];
void dfs(int x,int y,int now){
	book[x][y]=true;
	bool flag=true;
	for(int i=0;i<4;i++){
		int xx=x+fx[i][0],yy=y+fx[i][1];
		if(xx<1||yy<1||xx>n||yy>n||book[xx][yy]||mp[xx][yy]==now)continue;
		flag=false;
		dfs(xx,yy,lf(now));
	}
	if(flag)return;
}
string s;
int main(){
	cin>>n>>t;
	for(int i=1;i<=n;i++){
		cin>>s;
		for(int j=1;j<=n;j++)mp[i][j]=s[j-1];
	}
	while(t--){
		int x,y;
		cin>>x>>y;
		dfs(x,y,mp[x][y]);
		cout<<ans<<'\n';
	}
	Made by _3_14
}
2025/1/3 15:35
加载中...