Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<bits/stdc++.h>
- using namespace std;
- #define pi acos(-1.0)
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define ll long long
- #define pb push_back
- #define fi first
- #define se second
- #define in insert
- #define mp make_pair
- #define GCD(a,b) __gcd(a,b);
- #define endl "\n"
- #define FRU freopen("out.txt","w",stdout)
- #define FRO freopen("in.txt","r",stdin)
- #define INFLL 9223372036854775807
- #define all(x) (x).begin(),(x).end()
- #define MAXN 100001
- #define ar array
- #define lb lower_bound
- #define ub upper_bound
- #define minpq priority_queue<ll, vector<ll>, greater<ll>>
- #define maxpq priority_queue<ll>
- const int mxN=2e5;
- const int MOD=1e9+7;
- template<typename ForwardIterator, typename T>
- ForwardIterator first_less_than (ForwardIterator first, ForwardIterator last, T value)
- {auto it = std::lower_bound (first, last, value);
- return (it == first ? last : --it);}
- bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b)
- {
- return (a.second < b.second);
- }
- #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
- #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
- #define debug(x) cout<<#x<<" ";_print(x); cout<<endl;
- typedef unsigned long long ull;
- typedef long double lld;
- void _print(ll t) {cout << t;}
- void _print(int t) {cout << t;}
- void _print(string t) {cout << t;}
- void _print(char t) {cout << t;}
- void _print(lld t) {cout << t;}
- void _print(double t) {cout << t;}
- void _print(ull t) {cout << t;}
- template <class T, class V> void _print(pair <T, V> p);
- template <class T> void _print(vector <T> v);
- template <class T> void _print(set <T> v);
- template <class T, class V> void _print(map <T, V> v);
- template <class T> void _print(multiset <T> v);
- template <class T, class V> void _print(pair <T, V> p) {cout << "{"; _print(p.fi); cout << ","; _print(p.se); cout << "}";}
- template <class T> void _print(vector <T> v) {cout << "[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
- template <class T> void _print(set <T> v) {cout << "[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
- template <class T> void _print(multiset <T> v) {cout << "[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
- template <class T, class V> void _print(map <T, V> v) {cout << "[ "; for (auto i : v) {_print(i); cout << " ";} cout << "]";}
- //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
- #define pii pair<int,int>
- int fx[]={-2,-2,2,2,1,1,-1,-1};
- int fy[]={1,-1,1,-1,2,-2,2,-2};
- int cell[9][9];
- int d[9][9],vis[9][9];
- int row=8,col=8;
- void bfs(int sx,int sy)
- {
- memset(vis,0,sizeof vis);
- memset(d,0,sizeof d);
- vis[sx][sy]=1;
- queue<pii>q;
- q.push(pii(sx,sy));
- while(!q.empty())
- {
- pii top=q.front(); q.pop();
- for(int k=0;k<8;k++)
- {
- int tx=top.fi+fx[k];
- int ty=top.se+fy[k];
- if(tx>=0 and tx<row and ty>=0 and ty<col and vis[tx][ty]==0)
- {
- vis[tx][ty]=1;
- d[tx][ty]=d[top.fi][top.se]+1;
- q.push(pii(tx,ty));
- }
- }
- }
- }
- int main()
- {
- fastio;
- ll t,i,j;
- string s1,s2;
- while(cin>>s1>>s2)
- {
- ll x=s1[0]-'a';
- ll y=s1[1]-'1';
- bfs(x,y);
- ll a=s2[0]-'a';
- ll b=s2[1]-'1';
- cout<<"To get from "<<s1<<" to "<<s2<<" takes "<<d[a][b]<<" "<<"knight moves."<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement