TopCoder problem "MultiRead" used in SRM 305 (Division II Level One)



Problem Statement

    

In many computer systems, multiple processes can read from the same resource during the same clock cycle, but only a single process can write to the resource during a clock cycle. Reads and writes cannot be mixed during the same clock cycle. Given a history of the reads and writes that occurred during a particular computation as a String trace, and an int procs representing the number of processes used by the computation, calculate the minimum duration of the computation in clock cycles. The trace represents each read as an 'R' and each write as a 'W'.

For example, if trace is "RWWRRR" and procs is 3, then the minimum number of clock cycles is 4: one for the first read, one each for the two writes, and one for the last group of reads.

 

Definition

    
Class:MultiRead
Method:minCycles
Parameters:String, int
Returns:int
Method signature:int minCycles(String trace, int procs)
(be sure your method is public)
    
 

Constraints

-trace will contain between 1 and 50 characters, inclusive.
-Each character in trace will be 'R' or 'W'.
-procs will be between 1 and 10, inclusive.
 

Examples

0)
    
"RWWRRR"
3
Returns: 4
The example above.
1)
    
"RWWRRRR"
3
Returns: 5
Now the final group of 'R's takes two cycles.
2)
    
"WWWWW"
5
Returns: 5
3)
    
"RRRRRRRRRR"
4
Returns: 3
4)
    
"RWRRWWRWRWRRRWWRRRRWRRWRRWRRRRRRRRRWRWRWRRRRWRRRRR"
4
Returns: 30

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9826&pm=3526

Writer:

vorthys

Testers:

PabloGilberto , Olexiy , lovro , Andrew_Lazarev

Problem categories:

Simple Math