WHY???我是蒟蒻
  • 板块P1141 01迷宫
  • 楼主hyn281003
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/11/24 21:27
  • 上次更新2023/10/27 01:38:59
查看原帖
WHY???我是蒟蒻
695845
hyn281003楼主2022/11/24 21:27

为什么第一个非AC的数据自己测是对的,机器判是错的???

下面是代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
struct node{
	int x,y;
}Q,Node;
int n,m;
int Map[maxn][maxn];
bool Mark[maxn][maxn]={false};
int X[4]={0,0,1,-1};
int Y[4]={1,-1,0,0};
void R(){
    for(int i=1;i<=n;i++)
    	for(int j=1;j<=n;j++)Mark[i][j]=false;
}
bool jg(int x1,int y1,int x2,int y2){
	if(x1<1||x1>n||y1<1||y1>n)return false;
	if(Map[x1][y1]==Map[x2][y2]||Mark[x1][y1]==true)return false;
	return true;
}
int BFS(int x,int y){
	queue<node>q;
	int ans=1;
	Node.x=x;Node.y=y;
	Mark[x][y]=true;
	q.push(Node);
	while(!q.empty()){
		node top=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int newx=top.x+X[i];
			int newy=top.y+Y[i];
			if(jg(newx,newy,top.x,top.y)){
				Node.x=newx;Node.y=newy;
				q.push(Node);
				Mark[newx][newy]=true;
				ans++;
			}
		}
	}
	R();
	return ans;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
    	getchar();
        for(int j=1;j<=n;j++){
            Map[i][j]=getchar();
		}
	}
    while(m){
    	scanf("%d%d",&Q.x,&Q.y);
    	m--;
    	cout<<BFS(Q.x,Q.y)<<endl;
	}
	return 0;
}

救救我救救我救救我救救我救救我救救我救救我救救我救救我救救我救救我救救我救救我救救我救救我

2022/11/24 21:27
加载中...