Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
179715 C班 郑筱橦 机器人搬重物 C++ 通过 100 1 MS 396 KB 1598 2024-08-21 12:48:41

Tests(10/10):


#include<bits/stdc++.h> using namespace std; int n, m; int s[60][60]; int cf[60][60][4] = { 0 }; int a[4] = { -1,0,1,0 }; int b[4] = { 0,1,0,-1 }; class node { public: int x = 0, y = 0; int dir; int time = 0; }; node beginn, endd; queue<node> r; bool limit(int xx, int yy) { if (s[xx][yy]|| s[xx + 1][yy]|| s[xx][yy + 1]|| s[xx + 1][yy + 1]) return true; return false; } void bfs() { node temp; r.push(beginn); while (!r.empty()) { temp = r.front(); r.pop(); int t_x = temp.x; int t_y = temp.y; int dir = temp.dir; if (temp.x == endd.x && temp.y == endd.y) { cout << temp.time; exit(0); } if (cf[temp.x][temp.y][temp.dir] == 1) continue; cf[temp.x][temp.y][temp.dir] = 1; temp.time++; temp.dir = (dir + 3) % 4; r.push(temp); temp.dir = (dir + 5) % 4; r.push(temp); temp.dir = dir; for (int j = 1; j <= 3; j++) { int temp_x = t_x + a[dir] * j; int temp_y = t_y + b[dir] * j; if (temp_x <= 0 || temp_x >= n || temp_y <= 0 || temp_y >= m || limit(temp_x, temp_y))//判定可否移动以及边界 break; temp.x = temp_x; temp.y = temp_y; r.push(temp); } } } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> s[i][j]; cin >> beginn.x >> beginn.y; cin >> endd.x >> endd.y; char temp; cin >> temp; if (temp == 'N') beginn.dir = 0; else if (temp == 'S') beginn.dir = 2; else if (temp == 'E') beginn.dir = 1; else if (temp == 'W') beginn.dir = 3; bfs(); cout << -1; return 0; }


测评信息: