yesnomaybe's blog

By yesnomaybe, history, 4 years ago, In English

P0, P1, ...., Pn players in tournament. In first level, P0 plays with P1, P2 plays with P3 and so on. In level 2, Winner of P0,P1 plays with winner of P2,P3. For i,j output level in which they will face each other assuming they win all games.

  • Vote: I like it
  • -1
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Imagine the numbers 0 to n as the leaves of a binary tree of height ceil(log(n)). Suppose leaves are the level 0. After every match, a player moves up a level. So I think the level of LCA(as defined here) is the answer.

Could be wrong, I would solve it like this.