mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:28:48 +00:00
4318. 最短路径
https://www.acwing.com/problem/content/submission/code_detail/12517850/
This commit is contained in:
parent
a2eaf2838e
commit
09e60215e4
47
AcWing/4318/4318.cpp
Normal file
47
AcWing/4318/4318.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int to[5][2] = {{0, 0}, {0, -1}, {0, 1}, {-1, 0}, {1, 0}};
|
||||
|
||||
int x, y;
|
||||
std::string s;
|
||||
std::map<int, std::map<int, bool>> vis;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin >> s;
|
||||
vis[x][y] = true;
|
||||
for (char c : s) {
|
||||
int xx = 0, yy = 0;
|
||||
if (c == 'U') {
|
||||
y--;
|
||||
yy--;
|
||||
} else if (c == 'D') {
|
||||
y++;
|
||||
yy++;
|
||||
} else if (c == 'L') {
|
||||
x--;
|
||||
xx--;
|
||||
} else if (c == 'R') {
|
||||
x++;
|
||||
xx++;
|
||||
}
|
||||
|
||||
if (vis[x][y]) {
|
||||
cout << "NO" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
vis[x][y] = true;
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
vis[x + to[i][0] - xx][y + to[i][1] - yy] = true;
|
||||
}
|
||||
}
|
||||
cout << "YES" << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user