Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8. #include <queue>
  9. #include <stack>
  10. #include <math.h>
  11. #include <map>
  12. #include <set>
  13. #include <cstdlib>
  14. #include <utility>
  15. #include <iomanip>
  16. #include <cmath>
  17.  
  18. using namespace std;
  19. //#define forn(i,n) for(int i=0;i<n;++i)
  20. //#define all(v) (v).begin(), (v).end()
  21. typedef long long ll;
  22. typedef long double ld;
  23. typedef pair<int, int> pii;
  24. typedef pair<ll, ll> pll;
  25. typedef pair<double, double> pdd;
  26. typedef pair<ld, ld> plldd;
  27. typedef vector<pair<int, int > > vpii;
  28.  
  29. int const SIZE = 70, INF = 1e9;
  30.  
  31. void files() {
  32. //freopen("input.txt", "r", stdin);
  33. //freopen("output.txt", "w", stdout);
  34. }
  35. void fic() {
  36. //files();
  37. //setlocale(LC_ALL, "Russian");
  38. //cout.precision(20);
  39. ios_base::sync_with_stdio(false);
  40. cin.tie(0);
  41. }
  42.  
  43. struct edge {
  44. int from, to, weight;
  45. edge() {}
  46. edge(int from, int to, int weight) :
  47. from(from), to(to), weight(weight) {}
  48. };
  49.  
  50. int n = 8;
  51.  
  52. bool exist(int x, int y) {
  53. if (x < 0 || x >= n || y < 0 || y >= n)
  54. return false;
  55. return true;
  56. }
  57.  
  58. int dx[] = { 1, 1, 1, -1, -1, -1, 0, 0 };
  59. int dy[] = { 0, 1, -1, 0, 1, -1, -1, 1 };
  60. int size_d = 8;
  61.  
  62. int ans, cnt;
  63. char stx, fx;
  64. int starty, finishy, startx, finishx;
  65. //int used[110][110][110];
  66. queue<pair<pii, int>> q;
  67. //set<pii>used;
  68. /*void dfs(int xa, int ya, int time) {
  69. if (used.count({xa, ya}) || time > cnt || time>64) {
  70. used.insert({xa, ya});
  71. return;
  72. }
  73. if (time == cnt && ya == finishy && xa == finishx)ans++;
  74. used.insert({ xa, ya });
  75. for (int i = 0; i < size_d; i++) {
  76. int toX = xa + dx[i];
  77. int toY = ya + dy[i];
  78. if (exist(toX, toY) && !used.count({ toX, toY })) {
  79. dfs(toX, toY, time + 1);
  80. used.erase({ toX, toY });
  81. }
  82. }
  83. cout << ans;
  84. }*/
  85. int main() {
  86. fic();
  87. ans=0;
  88. cin >> stx >> starty >> fx >> finishy >> cnt;
  89. starty--, finishy--;
  90. startx = stx - 'A';
  91. finishx = fx - 'A';
  92. //used[startx][starty][0] = 1;
  93. set<pair<pii, int>>used;
  94. used.insert({ { startx, starty }, 0 });
  95. //dfs(startx, starty, 0);
  96. q.push({ { startx, starty}, 0 });
  97. while (!q.empty()) {
  98. int xa = q.front().first.first;
  99. int ya = q.front().first.second;
  100. int cn = q.front().second+1;
  101. if (cn > cnt)break;
  102. q.pop();
  103. for (int i = 0; i < size_d; ++i) {
  104. int toX = xa + dx[i];
  105. int toY = ya + dy[i];
  106. if (exist(toX, toY) /*&& !used.count({ {toX, toY}, cn})*/) {
  107. q.push({ { toX, toY}, cn });
  108. used.insert({ {toX, toY}, cn });
  109. }
  110. if (toX == finishx && toY == finishy && cn == cnt) {
  111. ans++;
  112. }
  113. //cout << ans<<" "<<cn<<"\n";
  114. }
  115.  
  116. }
  117. cout << ans;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement