1 条题解
-
0
#include <bits/stdc++.h> using namespace std; int main() { freopen("patrol.in", "r", stdin); freopen("patrol.out", "w", stdout); int H, W; cin >> H >> W; int r, c; cin >> r >> c; string grid[1005]; for (int i = 1; i <= H; i++){ cin >> grid[i]; } string s; cin >> s; int ignore = 0; int x = r, y = c; for (int i = 0; i < s.size(); i++){ char op = s[i]; int nx = x, ny = y; if (op == 'U') nx = x - 1; else if (op == 'D') nx = x + 1; else if (op == 'L') ny = y - 1; else if (op == 'R') ny = y + 1; bool ok = true; if (nx < 1 || nx > H) ok = false; if (ny < 1 || ny > W) ok = false; if (ok && grid[nx][ny - 1] == '#') ok = false; if (ok){ x = nx; y = ny; } else{ ignore++; } } cout << x << " " << y << " " << ignore << endl; fclose(stdin); fclose(stdout); return 0; }
- 1
信息
- ID
- 898
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 5
- 标签
- (无)
- 递交数
- 88
- 已通过
- 35
- 上传者