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

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

You are given a sequence of n bits of N 1’s (say “1111111111”)

There are four possible operations types:

Flip all the bits. Flip even position bits. Flip odd position bits. Flip the 3k+1 position bits. The initial configurations is always all 1’s.

Given number of operations, find all possible final configurations satisfying constraints given in input.

Input format:

N <- number of bits . 10 <= N <= 100

C <- number of operations allowed 1 <= C <= 10000

A <- comma separated list of positions which should be 1’s (list has 2 elements max)

This string contains -1 if no restriction on 1’s.

B <- comma separated list of positions which should be 0’s (list has 2 elements max)

This string contains -1 if no restriction on 0’s.

Output format:

It will be a string containing all final combinations separated by #, Combination of bits should be in numerical ascending order in the output string.

For example, if we have two final combinations '0110110110' and '0101010101' then the correct output will be "0101010101#0110110110" not "0110110110#0101010101".

NOTE: Strings are one-indexed.

Sample Test Case 1

Input

10 1 -1 7

Output

0000000000#0101010101#0110110110

Explanation

In this case, there are three possible final combinations:

All bits are 0s

1, 4, 7, 10 are 0s, and 2, 3, 5, 6, 8, 9 are 1′s.

1, 3, 5, 7, 9 are 0’s, and 2, 4, 6, 8, 10 are 1’s

Sample Test Case 2

Input

40 3 16 2,25

Output

0011100011100011100011100011100011100011

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

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

I hope I'm not misunderstanding the problem, but if it's simply flipping bits then the order of operations doesn't matter and so there is no sense in applying a single operation more than once. This directly yields 24 = 16 strings at most and you can check if each satisfies the constraints.

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

    Yes you are right!

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

    You are right. But given the number of operations allowed, can there be repeated operations? Only if an operation is repeated successively it cannot change the outcome. If they are repeated and in an unorderly fashion, various combinations of digits may arise.

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

      The operation order is irrelevant, from which follows my conclusion.

      You can imagine each operation being a XOR with a number. Options are:

      XOR with 1111111..

      XOR with 1010101..

      XOR with 0101010..

      XOR with 1001001..

      It is famously known and easy to prove that the order in which you apply XOR operations does not change the outcome.