TopCoder problem "ColorfulTilesEasy" used in SRM 472 (Division II Level One)



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 a String 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.
 

Definition

    
Class:ColorfulTilesEasy
Method:theMin
Parameters:String
Returns:int
Method signature:int theMin(String room)
(be sure your method is public)
    
 

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

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10940

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14154&pm=10940

Writer:

rng_58

Testers:

PabloGilberto , ivan_metelsky , Chmel_Tolstiy

Problem categories:

Greedy