官方题解|拼图
2025-08-18 00:24:00
发布于:浙江
44阅读
0回复
0点赞
T3
模拟
题目大意
现在我们有两种矩形,分别为 与 的矩形,矩形可以任意选择,问,能否拼成 的矩形。
题解思路
生成矩形的面积有什么性质。应该为偶数,接下来我们考虑 n , m 的取值;
我们定义
-
当 时, 应该满足是 的倍数。 (情况1)
-
当 时 ,我们注意到 时,所有的数都可以转换为 。那么我们考虑
的情况,其中 两个情况不可以。 (情况2) -
当 时,因为 是偶数 , 是偶数。一定可以。 (情况3)
-
当 时,可以用 的拼出。 (情况4)
-
当 , , 可以将图变成情况4 和情况 2 的组合, 一定可以。
-
当 , 是偶数 , , ,可以将图变成情况3 和情况 2 的组合, 一定可以。
复杂度分析
参考代码
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using i32 = int32_t;
#ifndef ONLINE_JUDGE
#include "test.h"
#else
#define debug(...) 42
#define debug_assert(...) 42
#endif
void solve() {
int n, m;
cin >> n >> m;
if (n > m) swap(n, m);
if (n * m % 2 == 1) {
cout << "No" << endl;
} else if (n == 1) {
if (m % 4 == 0) {
cout << "Yes" << endl;
} else cout << "No" << endl;
} else if (n == 2) {
if (m == 2 || m == 5) cout << "No" << endl;
else cout << "Yes" << endl;
} else {
cout << "Yes" << endl;
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
这里空空如也
有帮助,赞一个