Advertisement
Dennnhhhickk

Untitled

Mar 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9. long long a[8][8][100010], m;
  10. int dfs(int x, int y, int k)
  11. {
  12. if (k == 0)
  13. return 0;
  14. if (x < 8){
  15. a[x + 1][y][k - 1] += a[x][y][k];
  16. dfs(x + 1, y, k - 1);
  17. }
  18. if (x < 8 && y < 8)
  19. {
  20. a[x + 1][y + 1][k - 1] += a[x][y][k];
  21. dfs(x + 1, y + 1, k - 1);
  22. }
  23. if (y < 8){
  24. a[x][y + 1][k - 1] += a[x][y][k];
  25. dfs(x, y + 1, k - 1);
  26. }
  27. if (x > 1 && y < 8){
  28. a[x - 1][y + 1][k - 1] += a[x][y][k];
  29. dfs(x - 1, y + 1, k - 1);
  30. }
  31. if (x > 1){
  32. a[x - 1][y][k - 1] += a[x][y][k];
  33. dfs(x - 1, y, k - 1);
  34. }
  35. if (x > 1 && y > 1){
  36. a[x + 1][y - 1][k - 1] += a[x][y][k];
  37. dfs(x + 1, y - 1, k - 1);
  38. }
  39. if (y > 1){
  40. a[x][y - 1][k - 1] += a[x][y][k];
  41. dfs(x, y - 1, k - 1);
  42. }
  43. if (x < 8 && y > 1){
  44. a[x + 1][y - 1][k - 1] += a[x][y][k];
  45. dfs(x + 1, y - 1, k - 1);
  46. }
  47. }
  48.  
  49. int main()
  50. {
  51. int n, n1, ch, ch1, l = 0, r = 0, u = 0, d = 0, l1, r1, u1, d1, ans = 1;
  52. string s;
  53. getline(cin, s);
  54. cin >> m;
  55. for (int i = 0; i < 8; i++)
  56. for (int j = 0; j < 8; j++)
  57. a[i][j][m] = 0;
  58. ch = s[0] - 96;
  59. n = s[1] - 48;
  60. ch1 = s[3]- 96;
  61. n1 = s[4] - 48;
  62. l1 = ch;
  63. r1 = 7 - l1;
  64. d1 = n;
  65. u1 = 7 - d1;
  66. int tt;
  67. for (int i = 1; i <= m; i++){
  68. tt = 8;
  69. if (l1 == i)
  70. l = 1;
  71. if (r1 == i)
  72. r = 1;
  73. if (u1 == i)
  74. u = 1;
  75. if (d1 == i)
  76. d = 1;
  77. if (l)
  78. tt -= 3;
  79. if (r)
  80. tt -= 3;
  81. if (u)
  82. tt -= 3;
  83. if (d)
  84. tt -= 3;
  85. if (l && u)
  86. tt++;
  87. if (l && d)
  88. tt++;
  89. if (r && u)
  90. tt++;
  91. if (r && d)
  92. tt++;
  93. ans *= tt;
  94. }
  95. //cout << ch << " " << n << endl;
  96. //cin >> tt;
  97. a[ch - 1][n - 1][m] = 1;
  98. dfs(ch - 1, n - 1, m);
  99. long long ff = a[ch1 - 1][n1 - 1][0];
  100. //cout << ans << endl;
  101. /*for (int i = 0; i < 8; i++){
  102. for (int j = 0; j < 8; j++)
  103. cout << a[i][j][m] << " ";
  104. cout << endl;
  105. }*/
  106. cout << setprecision(6) << fixed << ff * 1.0 / ans << endl;
  107. return 0;
  108. }
  109. /*
  110. a1 b2
  111. 1
  112. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement