Salvens

Untitled

Jun 21st, 2023
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5. #include <vector>
  6. #include <set>
  7. using namespace std;
  8.  
  9. //#define int long long
  10. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11.  
  12. const long long INF = 1e18 + 7;
  13. const double EPS = 1e-9;
  14. const int N = 1e5 + 10;
  15. const int MOD = 1e9 + 7;
  16.  
  17. bool Rook(int x1, int y1, int x2, int y2) { // figure, target
  18.     return x1 == x2 || y1 == y2;
  19. }
  20.  
  21. bool Elephant(int x1, int y1, int x2, int y2) { // figure, target
  22.     return abs(x1 - x2) == abs(y1 - y2);
  23. }
  24.  
  25. bool Horse(int x1, int y1, int x2, int y2) { // figure, target
  26.     return abs(x1 - x2) + abs(y1 - y2) == 3 && abs(x1 - x2) && abs(y1 - y2);
  27. }
  28.  
  29. bool IsGood(int x, int y, int x1, int y1, int x2, int y2) {
  30.     if (x == x1 && y == y1 || x == x2 && y == y2) {
  31.         return false;
  32.     }
  33.     if (Rook(x1, y1, x2, y2) || Elephant(x2, y2, x1, y1)) {
  34.         return false;
  35.     }
  36.     if (Rook(x1, y1, x, y) && Elephant(x2, y2, x, y) && !Horse(x, y, x1, y1) && !Horse(x, y, x2, y2)) {
  37.         return true;
  38.     }
  39. }
  40.  
  41. void solve() {
  42.     int x, y;
  43.     char c;
  44.     cin >> c >> y;
  45.     x = (int)(c - 'a');
  46.     --y;
  47.     for (int x1 = 0; x1 < 8; ++x1) { // rook
  48.         for (int y1 = 0; y1 < 8; ++y1) {
  49.             for (int x2 = 0; x2 < 8; ++x2) { // elephant
  50.                 for (int y2 = 0; y2 < 8; ++y2) {
  51.                     if (IsGood(x, y, x1, y1, x2, y2)) {
  52.                         cout << char(x1 + 'a') << y1 + 1 << '\n';
  53.                         cout << char(x2 + 'a') << y2 + 1 << '\n';
  54.                         return;
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
  61.  
  62. int32_t main() {
  63.     IOS;
  64.  
  65.     int tt = 1;
  66.     while (tt--) {
  67.         solve();
  68.     }
  69.     return 0;
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment