1970: [USACO 2022 December Contest Bronze] Problem 2. Feeding the Cows
题目描述
Since all the cows are hungry, FJ decides to plant grassy patches on some of the positions . Guernseys and Holsteins prefer different types of grass, so if Farmer John decides to plant grass at some location, he must choose to planting either Guernsey-preferred grass or Holstein-preferred grass --- he cannot plant both at the same location. Each patch of grass planted can feed an unlimited number of cows of the appropriate breed.
Each cow is willing to move a maximum of (0) positions to reach a patch. Find the minimum number of patches needed to feed all the cows. Also, print a configuration of patches that uses the minimum amount of patches needed to feed the cows. Any configuration that satisfies the above conditions will be considered correct.
输入
Each test case starts with a line containing and . The next line will contain a string of length , where each character denotes the breed of the
th cow (G meaning Guernsey and H meaning Holstein).输出
样例输入
6
5 0
GHHGG
5 1
GHHGG
5 2
GHHGG
5 3
GHHGG
5 4
GHHGG
2 1
GH
样例输出
5
GHHGG
3
.GH.G
2
..GH.
2
...GH
2
...HG
2
HG
提示
Note that for some test cases, there are multiple acceptable configurations that manage to feed all cows while using the minimum number of patches. For example, in the fourth test case, another acceptable answer would be:
.GH..
This corresponds to placing a patch feeding Guernseys on the 2nd position and a patch feeding Holsteins on the third position. This uses the optimal number of patches and ensures that all cows are within 3 positions of a patch they prefer.
SCORING:
- Inputs 2 through 4 have .
- Inputs 5 through 8 have .
- Inputs 9 through 12 have .