7-98 3004 棋盘上的距离

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using pii = std::pair<i32, i32>;
using pll = std::pair<i64, i64>;
using vi = std::vector<i32>;
using vll = std::vector<i64>;
using vpii = std::vector<pii>;
using vpll = std::vector<pll>;

void solve();

int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

void solve()
{
    i32 t;
    std::cin >> t;
    bool endl = false;
    for (i32 i = 1; i <= t; ++i)
    {
        if (endl)
        {
            std::cout << '\n';
        }
        char col_1, row_1;
        char col_2, row_2;
        std::cin >> col_1 >> row_1 >> col_2 >> row_2;
        i32 col_move = std::abs(col_2 - col_1), row_move = std::abs(row_2 - row_1);
        if (col_move == 0 && row_move == 0)
        {
            std::cout << "0 0 0 0";
            continue;
        }
        // king_rule
        std::cout << std::max(row_move, col_move) << ' ';
        // queen_rule
        if (col_move == 0 || row_move == 0 || col_move == row_move)
        {
            std::cout << 1 << ' ';
        }
        else
        {
            std::cout << 2 << ' ';
        }
        // car_rule
        if (col_move == 0 || row_move == 0)
        {
            std::cout << 1 << ' ';
        }
        else
        {
            std::cout << 2 << ' ';
        }
        // guard_rule
        if (row_move == 0)
        {
            if (col_move % 2 == 0)
            {
                std::cout << 2;
            }
            else
            {
                std::cout << "Inf";
            }
        }
        else if (col_move == 0)
        {
            if (row_move % 2 == 0)
            {
                std::cout << 2;
            }
            else
            {
                std::cout << "Inf";
            }
        }
        else
        {
            if (row_move == col_move)
            {
                std::cout << 1;
            }
            else if ((row_move + col_move) % 2 == 1)
            {
                std::cout << "Inf";
            }
            else
            {
                std::cout << 2;
            }
        }
        endl = true;
    }
}
posted @ 2025-10-13 20:06  TPPPP72  阅读(6)  评论(0)    收藏  举报