Codeforces Round #734 (Div. 3)
作者:互联网
比赛链接
Codeforces Round #734 (Div. 3)
D1. Domino (easy version)
给你 \(t\) 组数据。对于每组数据给你一个 \(n \times m\) 的网格(\(n\) 为网格高度, \(m\) 为网格宽度,且网格的数量为偶数),要求在网格中放置多米诺骨牌,每个骨牌占据 \(1 \times 2\) 的网格区域。对于这 \(\frac{n m}{2}\) 个骨牌,要求正好有 \(k\) 个横着放置,而剩下的 \(\frac{n m}{2}-k\) 个竖着放置,正好铺满台面。现在要你给出对于每组 \(n, m\) 和 \(k\) ,是否有一种方案满足条件。如果有,输出 YES
,反之输出 NO
。
解题思路
构造
分情况讨论:
-
\(n,m\) 都为偶数时,此时可将整个矩形分为多个 \(2\times 2\) 的正方形,由于一个 \(2\times 2\) 的正方形只能同时放两个横或竖者的骨牌,所以要求 \(k\) 为偶数
-
\(n\) 为奇数,\(m\) 为偶数,先考虑 \(k\) 是否能将第一行填满,如不能填满,则不满足要求,\(\color{red}{为什么?}\)假设此时将 \(k\) 个横着的骨牌填满,则必定有一列没有骨牌,由于 \(n\) 为奇数,这时肯定不能只用竖着的骨牌来填,故不满足要求。如果可以填满此时可以忽略第一行,即转化为判断 \(n-1\) 行,\(m\) 列是否可以填满 \(k-m/2\) 个横着的的骨牌,即第一种情况
-
\(n\) 为奇数,\(m\) 为偶数,相当于判断 \(m\) 行,\(n\) 列是否可以填满 \(n*m/2-k\) 个横着的的骨牌,即第二种情况
代码
// Problem: D1. Domino (easy version)
// Contest: Codeforces - Codeforces Round #734 (Div. 3)
// URL: https://codeforces.com/contest/1551/problem/D1
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
// %%%Skyqwq
#include <bits/stdc++.h>
//#define int long long
#define help {cin.tie(NULL); cout.tie(NULL);}
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
int main()
{
int t,n,m,k;
for(cin>>t;t;t--)
{
cin>>n>>m>>k;
if(n%2==0&&m%2==0)
puts(k%2?"NO":"YES");
else if(n&1)
puts(k<m/2||(k-m/2)%2?"NO":"YES");
else
{
k=n*m/2-k;
puts(k<n/2||(k-n/2)%2?"NO":"YES");
}
}
return 0;
}
标签:填满,网格,Codeforces,偶数,734,骨牌,Div,define 来源: https://www.cnblogs.com/zyyun/p/16287010.html