程序出不来
  • 板块学术版
  • 楼主轮回·天照
  • 当前回复7
  • 已保存回复7
  • 发布时间2021/3/28 21:42
  • 上次更新2023/11/5 01:25:04
查看原帖
程序出不来
349592
轮回·天照楼主2021/3/28 21:42
#include <bits/stdc++.h>
using namespace std;
int maps[1001][1001],dir[4][2] = {{0,-1},{-1,0},{0,1},{1,0}};
int n,m;
void dfs(int x,int y){
	if(maps[x][y] <= 1)
		return;
	for(int i = 1;i <= 4;i++){
		int tx = x + dir[i][0];
		int ty = y + dir[i][1];
		if(tx < 1 || tx > n || ty < 1 || ty > m) continue;
		maps[tx][ty] = max(maps[tx][ty],maps[x][y] - 1);
		dfs(tx,ty);
		maps[x][y] = 1;
	}
}
int main(){
	cin >> n >> m;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			cin >> maps[i][j];
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			if(maps[i][j] > 1)
				dfs(i,j);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++)
			cout << maps[i][j] << " ";
		cout << endl;
	}
	return 0;
}

输入

7 7
1 0 0 0 0 0 1
0 2 0 0 3 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 2
0 0 2 0 0 0 0
0 3 0 0 2 0 2
1 0 0 2 0 0 1

后出不来,这是为什么

2021/3/28 21:42
加载中...