为什么我的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;
}