RGBColor
SRM 176 · 2003-12-22 · by Running Wild
Problem Statement
Although this generally works well, it doesn't generate good complements for grey colors that have all three components right around 128. To fix this you will return an alternate complement for grey colors. If each component of a color and its corresponding component of the color's complement differ by 32 or less, then make the complement of each component by either adding 128 to a component's value, or by subtracting 128 from a component's value, whichever one results in a legal value. For example, the color {120,130,140} would have the complement {125,105,115}, but each component in the color and the complement differ by 32 or less, so we make the complement {248,2,12}.
Create a class RGBColor with a method getComplement that takes a
Constraints
- rgb will contain exactly three elements.
- Each element of rgb will be a value between 0 and 255, inclusive.
{255,0,0}
Returns: { 0, 255, 255 }
The complement of red is cyan.
{115,115,143}
Returns: { 243, 243, 15 }
The complement of this bluish-grey would normally have been {140,140,112}. But since each component of the complement would have been within 32 of the corresponding component of rgb we return the alternate complement instead.
{115,115,144}
Returns: { 140, 140, 111 }
Also a bluish-grey, but in this case the blue component of the complement differs by 33 from the blue component of rgb, just enough so that we don't need to return the alternate complement.
{153,12,55}
Returns: { 102, 243, 200 }
{126,129,107}
Returns: { 129, 126, 148 }
Submissions are judged against all 48 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class RGBColor with a public method vector<int> getComplement(vector<int> rgb) · 48 test cases · 2 s / 256 MB per case