Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <cstring>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- long long a[8][8][100010], m;
- int main()
- {
- int n, n1, ch, ch1, l = 0, r = 0, u = 0, d = 0, l1, r1, u1, d1, ans = 1;
- string s;
- getline(cin, s);
- cin >> m;
- for (int i = 0; i < 8; i++)
- for (int j = 0; j < 8; j++)
- a[i][j][m] = 0;
- ch = s[0] - 96;
- n = s[1] - 48;
- ch1 = s[3]- 96;
- n1 = s[4] - 48;
- l1 = ch;
- r1 = 7 - l1;
- d1 = n;
- u1 = 7 - d1;
- int tt;
- for (int i = 1; i <= m; i++){
- tt = 8;
- if (l1 == i)
- l = 1;
- if (r1 == i)
- r = 1;
- if (u1 == i)
- u = 1;
- if (d1 == i)
- d = 1;
- if (l)
- tt -= 3;
- if (r)
- tt -= 3;
- if (u)
- tt -= 3;
- if (d)
- tt -= 3;
- if (l && u)
- tt++;
- if (l && d)
- tt++;
- if (r && u)
- tt++;
- if (r && d)
- tt++;
- ans *= tt;
- }
- //cout << ch << " " << n << endl;
- //cin >> tt;
- a[ch - 1][n - 1][m] = 1;
- for (int k = m; k > 0; k--)
- for (int x = 0; x < 8; x++)
- for (int y = 0; y < 8; y++){
- if (x > 0)
- a[x - 1][y][k - 1] += a[x][y][k];
- if (x < 7)
- a[x + 1][y][k - 1] += a[x][y][k];
- if (y > 0)
- a[x][y - 1][k - 1] += a[x][y][k];
- if (y < 7)
- a[x][y + 1][k - 1] += a[x][y][k];
- if (x > 0 && y > 0)
- a[x - 1][y - 1][k - 1] += a[x][y][k];
- if (x > 0 && y < 7)
- a[x - 1][y + 1][k - 1] += a[x][y][k];
- if (x < 7 && y > 0)
- a[x + 1][y - 1][k - 1] += a[x][y][k];
- if (x < 7 && y < 7)
- a[x + 1][y + 1][k - 1] += a[x][y][k];
- //cout << x << " " << y << " " << k << endl;
- }
- long long ff = a[ch1 - 1][n1 - 1][0];
- //cout << ff << " " << ans << endl;
- cout << setprecision(6) << fixed << ff * 1.0 / ans << endl;
- return 0;
- }
- /*
- a1 b2
- 1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement