Please read the new rule regarding the restriction on the use of AI tools. ×

TharunReddy323's blog

By TharunReddy323, 8 years ago, In English

The link for the problem PROBLEM

In this problem i found the XOR value of the (m+1)th player and each of the players m players from (1 to m) ,and found the number of 1's in the

binary form of the XOR output value.if the number of 1's are less than K then i incremented the counter.

but the approach is giving me wrong answer!

any suggestions to approach??

OR

Can anyone post a link or explain me an efficient way to convert a number from decimal to binary using bitmasks!!

| Write comment?
»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Remember that up to k different types of soldiers are allowed, so also if the number of ones is k increment the counter.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I did as mentioned but couldn't get the output?

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Submission

    I am getting TLE for the solution , I am thinking it is due to the large number of decimal to binary conversions involving in it , do have any efficient way to solve it !

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Your array has 101 elements and m is 1000.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I was going to say exactly what Neko29 said. You can also try using this method to count the number of 1 bits:

      unsigned int countSetBits(unsigned int n) { unsigned int count = 0; while(n) { count += n & 1; n >>= 1; } return count; }

      • »
        »
        »
        »
        8 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Also you can use __builtin_popcount(x) for counting number of 1 bits.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Check out this Code if you still need help.