Advertisement
mfgnik

Untitled

Dec 13th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <deque>
  5. #include <unordered_map>
  6. #include <unordered_set>
  7. #include <cmath>
  8. #include <iomanip>
  9. #include <utility>
  10. #include <string>
  11. #include <set>
  12. #include <map>
  13. #include <algorithm>
  14.  
  15. using namespace std;
  16.  
  17. bool comp(pair<int, bool> a, pair<int, bool> b) {
  18. return a.first <= b.first;
  19. }
  20.  
  21. int main() {
  22. int n, m, q, a, b, g, h;
  23. string s;
  24. unordered_map<string, pair<int, int>> c;
  25. c["N"] = {0, 1};
  26. c["S"] = {0, -1};
  27. c["E"] = {1, 0};
  28. c["W"] = {-1, 0};
  29. unordered_map<string, string> shifts;
  30. shifts["N"] = "E";
  31. shifts["E"] = "S";
  32. shifts["S"] = "W";
  33. shifts["W"] = "N";
  34. cin >> n >> m >> q >> a >> b;
  35. --a;
  36. --b;
  37. for (int i = 0; i < q; ++i) {
  38. cin >> g >> h >> s;
  39. --g;
  40. --h;
  41. vector<vector<bool>> d(n, vector<bool>(m, false));
  42. d[g][h] = true;
  43. d[a][b] = true;
  44. int cnt = 0;
  45. while (true) {
  46. if (g + c[s].first >= 0 && h + c[s].second >= 0 && !d[g + c[s].first][h + c[s].second]) {
  47. d[g + c[s].first][h + c[s].second] = true;
  48. g += c[s].first;
  49. h += c[s].second;
  50. cnt++;
  51. continue;
  52. }
  53. s = shifts[s];
  54. if (g + c[s].first >= 0 && h + c[s].second >= 0 && !d[g + c[s].first][h + c[s].second]) {
  55. d[g + c[s].first][h + c[s].second] = true;
  56. g += c[s].first;
  57. h += c[s].second;
  58. cnt++;
  59. continue;
  60. }
  61. cout << cnt << "\n";
  62. break;
  63. }
  64.  
  65. }
  66. return 0;
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement