蒟蒻求助!
  • 板块灌水区
  • 楼主kele20100413
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/9/7 22:53
  • 上次更新2023/11/4 07:17:57
查看原帖
蒟蒻求助!
343620
kele20100413楼主2021/9/7 22:53

为什么我的Dev-c++输出的和codeforces网站上评测机测试出的不一样??? 以下是原题链接: https://codeforces.com/problemset/problem/377/A 以下是我的代码:

#include<bits/stdc++.h>
using namespace std;
int di1[4]={0,0,-1,1};
int di2[4]={-1,1,0,0};
bool check(int n,int m,int x,int y){
	if((x<0)||(y<0)||(x>=n)||(y>=m)){
		return false;
	}
	return true;
}
int main(){
	int n,m,x;
	cin>>n>>m>>x;
	char maze[n][m];
	int step[n][m];
	bool visited[n][m];
	int startx,starty;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>maze[i][j];
			if(maze[i][j]=='.'){
				startx=i;
				starty=j;
			}
		}
	}
	int maxn=-1;
	queue<pair<int,int> > q;
	q.push(make_pair(startx,starty));
	while(!q.empty()){
		pair<int,int> c=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			if((check(n,m,c.first+di1[i],c.second+di2[i]))&&(visited[c.first+di1[i]][c.second+di2[i]]==0)&&maze[c.first+di1[i]][c.second+di2[i]]!='#'){
				q.push(make_pair(c.first+di1[i],c.second+di2[i]));
				visited[c.first+di1[i]][c.second+di2[i]]=1;
				step[c.first+di1[i]][c.second+di2[i]]=step[c.first][c.second]+1;
				maxn=max(step[c.first+di1[i]][c.second+di2[i]],maxn);
			}
		}
	}
	int now=0;
	while(1){
		int t=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(step[i][j]==maxn){
					maze[i][j]='X';
					step[i][j]=-1;
					now++;
					if(now==x){
						t=1;
						break;
					}
				}	
			}
			if(t==1)break;
		}
		if(t==1)break;
		maxn--;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout<<maze[i][j];
		}
		cout<<endl;
	}
	return 0;
}
2021/9/7 22:53
加载中...