Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- #define mh() make_heap()
- #define poph() pop_heap()
- #define pushh() push_heap()
- #define sor(n) n.begin(), n.end()
- #define rsor(n) n.rbegin(), n.rend()
- #define mp make_pair
- #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
- #define p(T) pair<T,T>
- #define znac(l) abs(l)/l
- const ll ok = ll(1e9 + 7);
- ll pole[9][9];
- void qbfs(ll x, ll y)
- {
- queue<p(ll)>next;
- next.push({ x, y });
- while (!next.empty())
- {
- p(ll) v = next.front();
- next.pop();
- x = v.first;
- y = v.second;
- for (int i = 1; i <= 8; i++)
- {
- if (pole[x][y] + 1 < pole[i][y])
- {
- next.push({ i,y });
- pole[i][y] = pole[x][y] + 1;
- }
- }
- for (int i = 1; i <= 8; i++)
- {
- if (pole[x][y] + 1 < pole[x][i])
- {
- next.push({ x,i });
- pole[x][i] = pole[x][y] + 1;
- }
- }
- int j;
- for(int i=x, j=y;i<=8&& j <= 8;i++, j++)
- if (pole[x][y] + 1 < pole[i][j])
- {
- next.push({ i,j });
- pole[i][j] = pole[x][y] + 1;
- }
- for (int i = x, j = y; i >=0&&j >=0; i--, j--)
- if (pole[x][y] + 1 < pole[i][j])
- {
- next.push({ i,j });
- pole[i][j] = pole[x][y] + 1;
- }
- for (int i = x, j = y; i >=0&&j <= 8; i--, j++)
- if (pole[x][y] + 1 < pole[i][j])
- {
- next.push({ i,j });
- pole[i][j] = pole[x][y] + 1;
- }
- for (int i = x, j = y; i <= 8&&j >=0; i++, j--)
- if (pole[x][y] + 1 < pole[i][j])
- {
- next.push({ i,j });
- pole[i][j] = pole[x][y] + 1;
- }
- }
- }
- void slbfs(ll x, ll y)
- {
- queue<p(ll)>next;
- next.push({ x, y });
- while (!next.empty())
- {
- p(ll) v = next.front();
- next.pop();
- x = v.first;
- y = v.second;
- int j;
- for (int i = x, j = y; i <= 8&&j <= 8; i++, j++)
- if (pole[x][y] + 1 < pole[i][j])
- {
- next.push({ i,j });
- pole[i][j] = pole[x][y] + 1;
- }
- for (int i = x, j = y; i >= 0&&j >= 0; i--, j--)
- if (pole[x][y] + 1 < pole[i][j])
- {
- next.push({ i,j });
- pole[i][j] = pole[x][y] + 1;
- }
- for (int i = x, j = y; i >= 0&&j <= 8; i--, j++)
- if (pole[x][y] + 1 < pole[i][j])
- {
- next.push({ i,j });
- pole[i][j] = pole[x][y] + 1;
- }
- for (int i = x, j = y; i <= 8&&j >= 0; i++, j--)
- if (pole[x][y] + 1 < pole[i][j])
- {
- next.push({ i,j });
- pole[i][j] = pole[x][y] + 1;
- }
- }
- }
- void kobfs(ll x, ll y)
- {
- queue<p(ll)>next;
- next.push({ x, y });
- while (!next.empty())
- {
- p(ll) v = next.front();
- next.pop();
- x = v.first;
- y = v.second;
- for (int i = 1; i <= 8; i++)
- {
- if (pole[x][y] + 1 < pole[i][y])
- {
- next.push({ i,y });
- pole[i][y] = pole[x][y] + 1;
- }
- }
- for (int i = 1; i <= 8; i++)
- {
- if (pole[x][y] + 1 < pole[x][i])
- {
- next.push({ x,i });
- pole[x][i] = pole[x][y] + 1;
- }
- }
- /*if (x + 2 <= 8 && y + 1 <= 8)
- {
- if (pole[x + 2][y + 1] > pole[x][y] + 1)
- {
- next.push({ x + 2,y + 1 });
- pole[x + 2][y + 1] = pole[x][y] + 1;
- }
- }
- if (x + 2 <= 8 && y -1 >=0)
- {
- if (pole[x + 2][y - 1] > pole[x][y] + 1)
- {
- next.push({ x + 2,y - 1 });
- pole[x + 2][y - 1] = pole[x][y] + 1;
- }
- }
- if (x - 2 >=0 && y + 1 <= 8)
- {
- if (pole[x - 2][y + 1] > pole[x][y] + 1)
- {
- next.push({ x - 2,y + 1 });
- pole[x - 2][y + 1] = pole[x][y] + 1;
- }
- }
- if (x - 2 >=0 && y - 1 >=0)
- {
- if (pole[x - 2][y - 1] > pole[x][y] + 1)
- {
- next.push({ x - 2,y - 1 });
- pole[x - 2][y - 1] = pole[x][y] + 1;
- }
- }
- if (y + 2 <= 8 && x + 1 <= 8)
- {
- if (pole[x + 1][y + 2] > pole[x][y] + 1)
- {
- next.push({ x + 1,y + 2 });
- pole[x + 1][y + 2] = pole[x][y] + 1;
- }
- }
- if (y + 2 <= 8 && x - 1 >= 0)
- {
- if (pole[x - 1][y + 2] > pole[x][y] + 1)
- {
- next.push({ x - 1,y + 2 });
- pole[x - 1][y + 2] = pole[x][y] + 1;
- }
- }
- if (y - 2 >=0 && x + 1 <= 8)
- {
- if (pole[x + 1][y - 2] > pole[x][y] + 1)
- {
- next.push({ x + 1,y - 2 });
- pole[x + 1][y - 2] = pole[x][y] + 1;
- }
- }
- if (y - 2 >=0 && x - 1 >= 0)
- {
- if (pole[x - 1][y - 2] > pole[x][y] + 1)
- {
- next.push({ x - 1,y - 2 });
- pole[x - 1][y - 2] = pole[x][y] + 1;
- }
- }*/
- }
- }
- void kbfs(ll x, ll y)
- {
- queue<p(ll)>next;
- next.push({ x, y });
- while (!next.empty())
- {
- p(ll) v = next.front();
- next.pop();
- x = v.first;
- y = v.second;
- if (x + 2 <= 8 && y + 1 <= 8)
- {
- if (pole[x + 2][y + 1] > pole[x][y] + 1)
- {
- next.push({ x + 2,y + 1 });
- pole[x + 2][y + 1] = pole[x][y] + 1;
- }
- }
- if (x + 2 <= 8 && y -1 >=0)
- {
- if (pole[x + 2][y - 1] > pole[x][y] + 1)
- {
- next.push({ x + 2,y - 1 });
- pole[x + 2][y - 1] = pole[x][y] + 1;
- }
- }
- if (x - 2 >=0 && y + 1 <= 8)
- {
- if (pole[x - 2][y + 1] > pole[x][y] + 1)
- {
- next.push({ x - 2,y + 1 });
- pole[x - 2][y + 1] = pole[x][y] + 1;
- }
- }
- if (x - 2 >=0 && y - 1 >=0)
- {
- if (pole[x - 2][y - 1] > pole[x][y] + 1)
- {
- next.push({ x - 2,y - 1 });
- pole[x - 2][y - 1] = pole[x][y] + 1;
- }
- }
- if (y + 2 <= 8 && x + 1 <= 8)
- {
- if (pole[x + 1][y + 2] > pole[x][y] + 1)
- {
- next.push({ x + 1,y + 2 });
- pole[x + 1][y + 2] = pole[x][y] + 1;
- }
- }
- if (y + 2 <= 8 && x - 1 >= 0)
- {
- if (pole[x - 1][y + 2] > pole[x][y] + 1)
- {
- next.push({ x - 1,y + 2 });
- pole[x - 1][y + 2] = pole[x][y] + 1;
- }
- }
- if (y - 2 >=0 && x + 1 <= 8)
- {
- if (pole[x + 1][y - 2] > pole[x][y] + 1)
- {
- next.push({ x + 1,y - 2 });
- pole[x + 1][y - 2] = pole[x][y] + 1;
- }
- }
- if (y - 2 >=0 && x - 1 >= 0)
- {
- if (pole[x - 1][y - 2] > pole[x][y] + 1)
- {
- next.push({ x - 1,y - 2 });
- pole[x - 1][y - 2] = pole[x][y] + 1;
- }
- }
- }
- }
- int main()
- {
- //files;
- string s;
- cin >> s;
- string h;
- cin >> h;
- ll x = h[0] - 'a' + 1;
- ll y = h[1] - '0';
- for (int i = 1; i <= 8; i++)
- {
- for (int j = 1; j <= 8; j++)
- {
- pole[i][j] = INT_MAX;
- }
- }
- pole[x][y] = 0;
- if (s == "queen")
- {
- qbfs(x, y);
- }
- else
- if (s == "bishop")
- {
- slbfs(x, y);
- }
- else
- {
- if(s=="hours")
- kbfs(x,y);
- else
- kobfs(x, y);
- }
- for (int i = 8; i >= 1; i--)
- {
- for (int j = 1; j <= 8; j++)
- {
- if (pole[j][i] == INT_MAX)
- cout << "*";
- else
- cout << pole[j][i];
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement