Блог пользователя zhin

Автор zhin, история, 23 месяца назад, По-английски

Question How to solve this ?

  • Проголосовать: нравится
  • -4
  • Проголосовать: не нравится

»
23 месяца назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

I'm pretty sure coding a greedy is worth a shot. If $$$x = y$$$, the answer is just $$$\frac{nx}{2}$$$; if $$$x \lt y$$$, remove all identical characters you can, then you are left with at most $$$26$$$ different characters, and you just remove those using the $$$y$$$ operation; if $$$x \gt y$$$, store character counts in a heap or a SortedList and always use $$$y$$$ on the max and second max frequency characters. If there is only $$$1$$$ distinct character left, use $$$x$$$ on it.

  • »
    »
    23 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    For the $$$x \gt y$$$ condition, a better method would be to just check if character having the max frequency has the frequency greater than sum of frequency of all the other characters , then the answer would be $$$x*\frac{(2*(max freq) - length of string)}{2} + y*((length of string)-(max freq))$$$ and other wise, it would be possible to cancel out all of the characters with some other character and it would be end up being $$$ \frac{ny}{2} $$$.