版本比较
P9909 Pingvin 题解
正文
增加 4 行删除 4 行
16 行未改动1718192021212223242526272829293031323334343536373839404142424344454611 行未改动16 行未改动 int n; cin >> n; int xs, ys, zs, xt, yt, zt; cin >> xs >> ys >> zs >> xt >> yt >> zt;//输入
for (int k = 1; k <= n; k++){ for (int i = 1; i <= n; i++){ string s; cin >> s;//输入 for (int j = 1; j <= n; j++) mp[i][j][k] = s[j-1] - '0';//注意顺序 } }
memset(vis, -1, sizeof(vis));//重置数组 queue<node> q;//栈 q.push({xs, ys, zs, 0}); vis[xs][ys][zs] = 0;
while (!q.empty()){ node now = q.front(); q.pop(); if (now.x == xt && now.y == yt && now.z == zt){//判断:如果当前位置为终点 cout << now.step << endl; return 0;//结束程序 }
for (int i = 0; i < 6; i++){ int nx = now.x + dx[i], ny = now.y + dy[i], nz = now.z + dz[i]; if (nx >= 1 && nx <= n && ny >= 1 && ny <= n && nz >= 1 && nz <= n){//边界条件 if (mp[nx][ny][nz] == 0 && vis[nx][ny][nz] == -1){//可以走11 行未改动