CF126E.Pills
省选/NOI-
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Doctor prescribed medicine to his patient. The medicine is represented by pills. Each pill consists of a shell and healing powder. The shell consists of two halves; each half has one of four colors — blue, red, white or yellow.
The doctor wants to put 28 pills in a rectangular box 7 × 8 in size. Besides, each pill occupies exactly two neighboring cells and any cell contains exactly one half of a pill. Thus, the result is a four colored picture 7 × 8 in size.
The doctor thinks that a patient will recover sooner if the picture made by the pills will be special. Unfortunately, putting the pills in the box so as to get the required picture is not a very easy task. That's why doctor asks you to help.
Doctor has some amount of pills of each of 10 painting types. They all contain the same medicine, that's why it doesn't matter which 28 of them will be stored inside the box.
Place the pills in the box so that the required picture was formed. If it is impossible to place the pills in the required manner, then place them so that the number of matching colors in all 56 cells in the final arrangement and the doctor's picture were maximum.
医生为患者开具了药物。该药物以药丸形式呈现。每粒药丸由外壳和治疗性药粉组成。外壳由两个半壳构成;每个半壳具有四种颜色之一:蓝色、红色、白色或黄色。
医生希望将 28 粒药丸放入一个 7×8 的矩形药盒中。此外,每粒药丸恰好占据两个相邻的格子,且每个格子中恰好包含一粒药丸的一个半壳。因此,最终得到一幅 7×8 的四色图案。
医生认为,若药丸在盒中所形成的图案具有某种特殊性,则患者将更快康复。遗憾的是,将药丸按要求放入盒中以获得目标图案并非易事。因此,医生请求你提供帮助。
医生拥有 10 种涂装类型的药丸(即 10 种半壳颜色组合),每种类型均有若干粒。这些药丸所含药物完全相同,因此最终放入盒中的 28 粒药丸具体是哪 28 粒并不重要。
请将药丸放入药盒中,使得最终形成的图案与医生指定的目标图案完全一致。若无法实现完全匹配,则应使最终排列中全部 56 个格子的颜色与目标图案中对应格子的颜色一致的数量最大化。
输入格式
First 7 lines contain the doctor's picture. Each line contains 8 characters, each character can be "B", "R", "W" and "Y" that stands for blue, red, white and yellow colors correspondingly.
Next four lines contain 10 numbers that stand for, correspondingly, the number of pills painted:
"BY" "BW" "BR" "BB"
"RY" "RW" "RR"
"WY" "WW"
"YY"
Those numbers lie within range from 0 to 28 inclusively. It is guaranteed that the total number of pills in no less than 28.
前 7 行包含医生的图案。每行包含 8 个字符,每个字符可以是 "B"、"R"、"W" 或 "Y",分别代表蓝色、红色、白色和黄色。
接下来的四行包含 10 个数字,依次表示被涂成以下颜色的药丸数量:
"BY" "BW" "BR" "BB"
"RY" "RW" "RR"
"WY" "WW"
"YY"
这些数字均在 0 到 28(含端点)范围内。保证药丸总数不少于 28。
输出格式
Print on the first line the maximal number cells for which the colors match.
Then print 13 lines each containing 15 characters — the pills' position in the optimal arrangement. The intersections of odd lines and odd columns should contain characters "B", "R", "W" and "Y". All other positions should contain characters ".", "-" and "|". Use "-" and "|" to show which halves belong to one pill. See the samples for more clarification.
If there are several possible solutions, print any of them.
第一行输出颜色匹配的单元格的最大数量。
随后输出 13 行,每行包含 15 个字符——表示最优排列下药丸的位置。奇数行与奇数列的交点处应为字符 "B"、"R"、"W" 或 "Y"。其余所有位置应为字符 "."、"-" 或 "|"。使用 "-" 和 "|" 表示属于同一药丸的两个半块。更多细节请参见样例。
若存在多种可能的解,输出任意一种即可。
输入输出样例
输入#1
WWWBBWWW WWWBBWWW YYWBBWWW YYWBBWRR YYWBBWRR YYWBBWRR YYWBBWRR 0 0 0 8 0 1 5 1 10 5
输出#1
53 W.W.W.B.B.W.W.W |.|.|.|.|.|.|.| W.W.W.B.B.W.W.W ............... Y.Y.W.B.B.W.W-W |.|.|.|.|.|.... Y.Y.W.B.B.W.R.R ............|.| Y.Y.W.B.B.R.R.R |.|.|.|.|.|.... Y.Y.W.B.B.W.R.R ............|.| Y-Y.B-B.B-B.R.R
输入#2
WWWWWWWW WBYWRBBY BRYRBWYY WWBRYWBB BWWRWBYW RBWRBWYY WWWWWWWW 0 0 0 1 0 0 1 0 1 25
输出#2
15 W.Y.Y-Y.Y-Y.Y-Y |.|............ W.Y.Y.Y.Y.B-B.Y ....|.|.|.....| Y-Y.Y.Y.Y.Y-Y.Y ............... Y.Y.Y.R.Y.Y.Y-Y |.|.|.|.|.|.... Y.Y.Y.R.Y.Y.Y.Y ............|.| Y-Y.Y.Y-Y.Y.Y.Y ....|.....|.... Y-Y.Y.Y-Y.Y.Y-Y
输入解题思路,AI测评打分。不知道怎么写?