Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef pair<int,int> pii;
- int dis[120][120], n;
- pii operations[8] = {{1, 2}, {1, -2}, {2, 1}, {2, -1}, {-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}};
- int main() {
- freopen("test.txt", "r", stdin);
- cin.sync_with_stdio(0); cin.tie(0);
- cin >> n;
- for(int i = 0, r, c, pr, pc, kr, kc; i<n; i++) {
- cin >> r >> c >> pr >> pc >> kr >> kc;
- bool win = false, stalemate = false;
- memset(dis, -1, sizeof(dis));
- dis[kr][kc] = 0;
- queue<pii> q; q.push({kr, kc});
- while(!q.empty()) {
- pii cur = q.front(); q.pop();
- for(pii o : operations) {
- pii ne = {cur.first+o.first, cur.second+o.second};
- if(ne.first <= r && ne.first >= 1 && ne.second <= c && ne.second >= 1) {
- if(dis[ne.first][ne.second] == -1) {
- dis[ne.first][ne.second] = dis[cur.first][cur.second]+1;
- q.push({ne.first, ne.second});
- }
- }
- }
- }
- int winMove = r+1, staleMove = r+1;
- for(int i=pr; i<r; i++){
- int t = i - pr;
- if(dis[i][pc] >= 0 && dis[i][pc] <= t && (t-dis[i][pc])%2 == 0){
- win = true; winMove = t; break;
- }
- if(!stalemate && dis[i+1][pc] >= 0 && dis[i+1][pc] <= t+1 && (t-dis[i+1][pc])%2 == 0){
- stalemate = true; staleMove = t;
- }
- }
- if(win) {
- cout << "Win in " << winMove << " knight move(s)." << "\n";
- }
- else if(stalemate) {
- cout << "Stalemate in " << staleMove << " knight move(s)." << "\n";
- }
- else {
- cout << "Loss in " << r - pr - 1 << " knight move(s)." << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement