CF1551D2.Domino (hard version)
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The only difference between this problem and D1 is that you don't have to provide the way to construct the answer in D1, but you have to do it in this problem.
There's a table of n×m cells (n rows and m columns). The value of n⋅m is even.
A domino is a figure that consists of two cells having a common side. It may be horizontal (one of the cells is to the right of the other) or vertical (one of the cells is above the other).
You need to place 2nm dominoes on the table so that exactly k of them are horizontal and all the other dominoes are vertical. The dominoes cannot overlap and must fill the whole table.
本题与 D1 的唯一区别在于:D1 中你无需给出构造方案,而本题中你必须提供构造方案。
有一个 n×m 的表格(共 n 行、m 列),且满足 n⋅m 为偶数。
一个骨牌(domino)是由两个具有公共边的格子组成的图形。它可以是水平放置的(其中一个格子位于另一个格子右侧),也可以是垂直放置的(其中一个格子位于另一个格子上方)。
你需要在表格中放置 2nm 个骨牌,使得其中恰好 k 个为水平骨牌,其余全部为垂直骨牌。骨牌之间不能重叠,且必须完全覆盖整个表格。
输入格式
The first line contains one integer t (1≤t≤10) — the number of test cases. Then t test cases follow.
Each test case consists of a single line. The line contains three integers n, m, k (1≤n,m≤100, 0≤k≤2nm, n⋅m is even) — the count of rows, columns and horizontal dominoes, respectively.
第一行包含一个整数 t(1≤t≤10)—— 测试用例的数量。随后是 t 个测试用例。
每个测试用例由一行组成。该行包含三个整数 n、m、k(1≤n,m≤100,0≤k≤2nm,且 n⋅m 为偶数)—— 分别表示行数、列数和水平多米诺骨牌的数量。
输出格式
For each test case:
- print "NO" if it's not possible to place the dominoes on the table in the described way;
- otherwise, print "YES" on a separate line, then print n lines so that each of them contains m lowercase letters of the Latin alphabet — the layout of the dominoes on the table. Each cell of the table must be marked by the letter so that for every two cells having a common side, they are marked by the same letters if and only if they are occupied by the same domino. I.e. both cells of the same domino must be marked with the same letter, but two dominoes that share a side must be marked with different letters. If there are multiple solutions, print any of them.
对于每个测试用例:
- 如果无法按上述方式将多米诺骨牌放置在桌面上,则输出
"NO"; - 否则,先单独一行输出
"YES",然后输出 n 行,每行包含 m 个小写拉丁字母——表示桌面上多米诺骨牌的布局。桌面的每个格子必须用一个字母标记,使得:对于任意两个具有公共边的格子,它们被标记为相同字母当且仅当它们被同一块多米诺骨牌占据。即:同一块多米诺骨牌所占的两个格子必须标记为相同的字母,而两块相邻(有公共边)的多米诺骨牌必须标记为不同的字母。若存在多种解法,输出任意一种即可。
输入输出样例
输入#1
8 4 4 2 2 3 0 3 2 3 1 2 0 2 4 2 5 2 2 2 17 16 2 1 1
输出#1
YES accx aegx bega bdda YES aha aha YES zz aa zz NO YES aaza bbza NO YES bbaabbaabbaabbaay ddccddccddccddccy NO
输入解题思路,AI测评打分。不知道怎么写?