ColorfulTilesEasy
SRM 472 · 2009-11-12 · by rng_58
SRM 472 · 2009-11-12 · by rng_58 · Greedy
Problem Statement
Problem Statement
Taro likes colorful things, especially colorful tiles.
Taro's room is divided into L square tiles arranged in a row. Each tile is one of the following four colors: red, green, blue or yellow. You are given aString room. If the i-th character of room is 'R', 'G', 'B' or 'Y', the color of the i-th tile is red, green, blue or yellow, respectively.
He decided to change the color of some tiles so that no two adjacent tiles have the same color. Return the minimal number of tiles he must change.
Taro's room is divided into L square tiles arranged in a row. Each tile is one of the following four colors: red, green, blue or yellow. You are given a
He decided to change the color of some tiles so that no two adjacent tiles have the same color. Return the minimal number of tiles he must change.
Constraints
- room will contain between 1 and 10 characters, inclusive.
- Each character in room will be 'R', 'G', 'B' or 'Y'.
Examples
0)
"RRRRRR" Returns: 3
For example, he can change three tiles in the following way: "RRRRRR" -> "RGRGRG".
1)
"GGGGGGG" Returns: 3
For example, "GGGGGGG" -> "GRGRGRG".
2)
"BBBYYYYYY" Returns: 4
For example, "BBBYYYYYY" -> "BRBYRYRYR".
3)
"BRYGYBGRYR" Returns: 0
The condition is already satisfied, so he doesn't need to change any tiles.
4)
"RGGBBBRYYB" Returns: 3
Submissions are judged against all 69 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class ColorfulTilesEasy with a public method int theMin(string room) · 69 test cases · 2 s / 256 MB per case