Блог пользователя v-O_O-v

Автор v-O_O-v, история, 5 лет назад, По-английски

Does anyone have a simpler approach of solving this problem? Please share with me.

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

if u can understand python the refer to my solution https://codeforces.com/contest/1152/submission/53235674 starting from MSB following a greedy type appraoch

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +2 Проголосовать: не нравится

    Can you explain your logic I have difficulty in reading python. Thanks!

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      first of all i converted the number into its binary and then checked if all bits are set if not then i start traversing from the most significant bit if a bit is set then continue else i calculated the length of all the bits starting from that '0' bit and then xored it with the number(all bits set with the lenght i calculated) AND then checked if the number becomes 2^n-1 (break if yes) else continue till the number becomes 2^n-1 (till we reach the last bit). take an example and u will understand refering to my code

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      sorry for the down vote by mistake:)