TopCoder problem "CrazyCompetition" used in TCHS07 Alpha Round 1 (Division I Level Three)



Problem Statement

    

One of the most famous and most dangerous competitions is Crazy Competition. Crazy Competition 2007 will take place in Antarctica and consist of two phases: Summer and Winter. The Summer phase lasts for daysSummer consecutive days and the Winter phase lasts for daysWinter consecutive days. The two phases cannot overlap. You are in charge of scheduling the two phases, and your goal is to maximize the difference between the average temperatures of the two phases (i.e., the average temperature during the Summer phase minus the average temperature during the Winter phase).

You are given the temperatures for every day of a single year in a String[]. Concatenate the elements of the String[] into one long string. The i-th character of this string represents the temperature on the i-th day of 2007. The first and last days are not considered consecutive. Characters 'A' through 'Z' represent temperatures -1 through -26. The character '0' (zero) represents the temperature 0. Characters 'a' through 'z' represent temperatures 1 through 26. Return the maximum possible difference between the average temperatures of the two phases.

 

Definition

    
Class:CrazyCompetition
Method:differenceTemperature
Parameters:int, int, String[]
Returns:double
Method signature:double differenceTemperature(int daysSummer, int daysWinter, String[] temperature)
(be sure your method is public)
    
 

Notes

-The returned value must be accurate to 1e-9 relative or absolute.
 

Constraints

-temperature will contain between 1 and 50 elements, inclusive.
-Each element of temperature will contain between 1 and 50 characters, inclusive.
-temperature will contain only lowercase letters ('a'-'z'), uppercase letters ('A'-'Z'), and '0' (zero) characters.
-daysSummer and daysWinter will be greater than 0 and (daysSummer + daysWinter) will be less than or equal to the number of characters in temperature.
 

Examples

0)
    
1
1
{"aa"}
Returns: 0.0
1)
    
1
1
{"ba"}
Returns: 1.0
Summer have to be warmer. (first day)
2)
    
1
1
{"az"}
Returns: 25.0
Summer have to be warmer. (second day)
3)
    
2
3
{"aaaa","x"}
Returns: 11.5
4)
    
2
3
{"a","a","a","a","x"}
Returns: 11.5
Same as previous example.
5)
    
4
1
{"00A00"}
Returns: -0.25
Summer phase is colder than Winter phase.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10702&pm=7522

Writer:

VitalyGoldstein

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Search