Sunday, February 23, 2014

SPOJ 13046. The Glittering Caves of Aglarond


here is one statement which will make this task a lot easier. Every time we are required to click on switch, I say we should click a row which has the minimum number of on turned lights. Why?
because if there number of ON switches is less then the half of the row then we will "win" a few more lights (by saying win I mean get a better number) , if the number of ON turned switches is more then the half we will have the minimum "lose" note that every time we click a switch the OFF turned lights become ON and the rest ON turned lights become of, in other words if we have on ON lights and off OFF lights then after switching them on=N-on, off=N-off. So every time we can just sort them sort them by the number of OFF turned switches and take the minimum one and switch it , this way we will minimize the "loss" and maximize the "profit".

       DOWNLOAD THE FULL SOURCE CODE

No comments:

Post a Comment