解法1:暴力
解法2:
原问题状态空间:n -> ∞,m -> ∞。
由于n 与 m对称,所以先考虑n。
我们将状态空间缩小,其答案显而易见。由于n * m矩阵的扩展具有相似性和对称性,我们可以将特殊解的应用场景扩大到原问题的状态空间。
当 n = 1 m -> ∞ 时,ans = 任意一点坐标;
当 n = 2 m->∞时,无解。
当m <= 3时,有解,ans = 中间位置点的坐标。
当m = 4时,无解。
所以有解情况并不多。
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const int mod = 1e9 + 7;
const int N = 2e6 + 10, M = 2 * N, P = 131;
int n, m;
void solve()
{
//输入:
cin >> n >> m;
if(n == 1 || m == 1) cout << 1 << " " << 1 << endl;
else cout << 2 << " " << 2 << endl;
}
int main(){
std::ios::sync_with_stdio(false);std::cin.tie(0);
int T; cin >> T; while(T -- ){solve();}}