题解:P10713 【MX-X1-T1】「KDOI-05」简单的无限网格问题

· · 题解

分类讨论题。

由于 n,m\ge 2,可知一定存在合理的构造方案。

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int a, b, s;
    cin >> a >> b;
    if (a % 2 == 1 && b % 2 == 0) cout << 2;
    else if (a % 2 == 1 && b % 2 == 1) cout << 3;
    else if (a % 2 == 0 && b % 2 == 1) cout << 2;
    else cout << 3;
    cout << endl;
    return;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}