Advertisement
Dennnhhhickk

Untitled

Mar 16th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 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.  
  11. int main()
  12. {
  13. int n, n1, ch, ch1, l = 0, r = 0, u = 0, d = 0, l1, r1, u1, d1, ans = 1;
  14. string s;
  15. getline(cin, s);
  16. cin >> m;
  17. for (int i = 0; i < 8; i++)
  18. for (int j = 0; j < 8; j++)
  19. a[i][j][m] = 0;
  20. ch = s[0] - 96;
  21. n = s[1] - 48;
  22. ch1 = s[3]- 96;
  23. n1 = s[4] - 48;
  24. l1 = ch;
  25. r1 = 7 - l1;
  26. d1 = n;
  27. u1 = 7 - d1;
  28. int tt;
  29. for (int i = 1; i <= m; i++){
  30. tt = 8;
  31. if (l1 == i)
  32. l = 1;
  33. if (r1 == i)
  34. r = 1;
  35. if (u1 == i)
  36. u = 1;
  37. if (d1 == i)
  38. d = 1;
  39. if (l)
  40. tt -= 3;
  41. if (r)
  42. tt -= 3;
  43. if (u)
  44. tt -= 3;
  45. if (d)
  46. tt -= 3;
  47. if (l && u)
  48. tt++;
  49. if (l && d)
  50. tt++;
  51. if (r && u)
  52. tt++;
  53. if (r && d)
  54. tt++;
  55. ans *= tt;
  56. }
  57. //cout << ch << " " << n << endl;
  58. //cin >> tt;
  59. a[ch - 1][n - 1][m] = 1;
  60. for (int k = m; k > 0; k--)
  61. for (int x = 0; x < 8; x++)
  62. for (int y = 0; y < 8; y++){
  63. if (x > 0)
  64. a[x - 1][y][k - 1] += a[x][y][k];
  65. if (x < 7)
  66. a[x + 1][y][k - 1] += a[x][y][k];
  67. if (y > 0)
  68. a[x][y - 1][k - 1] += a[x][y][k];
  69. if (y < 7)
  70. a[x][y + 1][k - 1] += a[x][y][k];
  71. if (x > 0 && y > 0)
  72. a[x - 1][y - 1][k - 1] += a[x][y][k];
  73. if (x > 0 && y < 7)
  74. a[x - 1][y + 1][k - 1] += a[x][y][k];
  75. if (x < 7 && y > 0)
  76. a[x + 1][y - 1][k - 1] += a[x][y][k];
  77. if (x < 7 && y < 7)
  78. a[x + 1][y + 1][k - 1] += a[x][y][k];
  79. //cout << x << " " << y << " " << k << endl;
  80. }
  81. long long ff = a[ch1 - 1][n1 - 1][0];
  82. //cout << ff << " " << ans << endl;
  83. cout << setprecision(6) << fixed << ff * 1.0 / ans << endl;
  84. return 0;
  85. }
  86. /*
  87. a1 b2
  88. 1
  89. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement