CF142C.Help Caretaker
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):
### ..# .#. #..
.#. ### .#. ###
.#. ..# ### #..
Simon faced a quite natural challenge: placing in the given n × m cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.
Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?
秋天姗姗来迟,降临在“远在天边王国”(Far Far Away)。今年丰收丰盛,如今正是为寒冬做准备的时候。当大多数人欢庆丰收节时,看守员西蒙(Simon)却正面临一项极其棘手的任务:如何在仓库中为农用设备安排存放空间。
他遇到了一个特别大型的设备——涡轮犁(turboplow)——的存放难题。问题在于,涡轮犁存放时所占据的空间并非简单的矩形,而是呈“T”字形,如下图中四幅图之一所示(其中字符 # 表示涡轮犁所占单元格,字符 . 表示空闲单元格):
### ..# .#. #..
.#. ### .#. ###
.#. ..# ### #..
西蒙面临一个十分自然的挑战:在给定的 n×m 单元格大小的仓库中,尽可能多地放置涡轮犁。在放置过程中,涡轮犁可任意旋转(即其占据的空间形状必须与上述四幅图之一完全一致)。然而,任意两个涡轮犁不得“重叠”,即它们不能占据仓库中的同一单元格。
西蒙感到单凭自己无法找出一种最优的摆放方式,以使涡轮犁的数量最大化。你能帮他吗?
输入格式
The only line contains two space-separated integers n and m — the sizes of the warehouse (1 ≤ n, m ≤ 9).
唯一的一行包含两个用空格分隔的整数 n 和 m —— 仓库的尺寸(1 ≤ n, m ≤ 9)。
输出格式
In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next n lines print m characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.
第一行输出仓库中最多可放置的涡轮犁数量。接下来的 n 行中,每行输出 m 个字符:用 “.”(英文句点)表示空位,用连续的大写拉丁字母(第一个涡轮犁用 “A”,第二个用 “B”,依此类推,直至你方案中涡轮犁的总数)表示对应涡轮犁的位置(这些涡轮犁按最优方式放置在仓库中)。对涡轮犁位置的编号顺序无要求。若给定尺寸的仓库存在多个最优解,输出其中任意一个即可。
输入输出样例
输入#1
3 3
输出#1
1 AAA .A. .A.
输入#2
5 6
输出#2
4 A..C.. AAAC.. ABCCCD .B.DDD BBB..D
输入#3
2 2
输出#3
0 .. ..
输入解题思路,AI测评打分。不知道怎么写?