rand_everything @ 2022-08-28 20:36:59
#include <cstring>
#define N 310
using namespace std;
int m,t[N][N],s[N][N];
int ex[4] = {0,-1,1,0},ey[4] = {1,0,0,-1};
void dfs(int x,int y,int t){
cout << x <<" "<< y<<" " << t << endl;
//int nt = t[x][y];
//cout <<endl << x <<" "<< y;
if(s[x][y] == -1){
/*for(int i = 0;i < 5;i++){
for(int j = 0;j < 5;j++){
cout << t[i][j] << " ";
}
cout << endl;
}
cout << endl;*/
cout << t;
return;
}
for(int i = 0;i < 4;i++){
int dx = x + ex[i],dy = y + ey[i];
//cout << dx << " " << dy << endl;
if(dx >= 0 && dy >= 0 && s[dx][dy] > t){
//int cnt = t[dx][dy];
//t[dx][dy] == nt + 1;
dfs(dx,dy,t+1);
//t[dx][dy] == cnt;
}
}
}
int main(){
cin >> m;
memset(s,-1,sizeof s);
for(int i = 1;i <= m;i++){
int xx,yy,tt;
cin >> xx >> yy >> tt;
if(s[xx][yy] == -1){
s[xx][yy] = tt;
}else{
s[xx][yy] = min(s[xx][yy],tt);
}
for(int i = 0;i < 4;i++){
int dx = xx + ex[i],dy = yy + ey[i];
if(dx >= 0 && dy >= 0){
if(s[dx][dy] == -1){
s[dx][dy] = tt;
}else{
s[dx][dy] = min(s[dx][dy],tt);
}
}
}
}
//t[0][0] = 0;
cout << endl;
dfs(0,0,0);
cout << endl;
for(int i = 0;i < 5;i++){
for(int j = 0;j < 5;j++){
cout << s[i][j] << " ";
}
cout << endl;
}
return 0;
}
by 喵仔牛奶 @ 2022-08-28 20:45:25
tlqtj,jbl