Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef pair<int,int> pii;
  4. int dis[120][120], n;
  5. pii operations[8] = {{1, 2}, {1, -2}, {2, 1}, {2, -1}, {-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}};
  6. int main() {
  7. freopen("test.txt", "r", stdin);
  8. cin.sync_with_stdio(0); cin.tie(0);
  9. cin >> n;
  10. for(int i = 0, r, c, pr, pc, kr, kc; i<n; i++) {
  11. cin >> r >> c >> pr >> pc >> kr >> kc;
  12. bool win = false, stalemate = false;
  13. memset(dis, -1, sizeof(dis));
  14. dis[kr][kc] = 0;
  15. queue<pii> q; q.push({kr, kc});
  16. while(!q.empty()) {
  17. pii cur = q.front(); q.pop();
  18. for(pii o : operations) {
  19. pii ne = {cur.first+o.first, cur.second+o.second};
  20. if(ne.first <= r && ne.first >= 1 && ne.second <= c && ne.second >= 1) {
  21. if(dis[ne.first][ne.second] == -1) {
  22. dis[ne.first][ne.second] = dis[cur.first][cur.second]+1;
  23. q.push({ne.first, ne.second});
  24. }
  25. }
  26. }
  27. }
  28. int winMove = r+1, staleMove = r+1;
  29. for(int i=pr; i<r; i++){
  30. int t = i - pr;
  31. if(dis[i][pc] >= 0 && dis[i][pc] <= t && (t-dis[i][pc])%2 == 0){
  32. win = true; winMove = t; break;
  33. }
  34. if(!stalemate && dis[i+1][pc] >= 0 && dis[i+1][pc] <= t+1 && (t-dis[i+1][pc])%2 == 0){
  35. stalemate = true; staleMove = t;
  36. }
  37. }
  38. if(win) {
  39. cout << "Win in " << winMove << " knight move(s)." << "\n";
  40. }
  41. else if(stalemate) {
  42. cout << "Stalemate in " << staleMove << " knight move(s)." << "\n";
  43. }
  44. else {
  45. cout << "Loss in " << r - pr - 1 << " knight move(s)." << "\n";
  46. }
  47. }
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement