Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
People 1 to 10 stand in a circle. Starting from person 1, every second person is eliminated until one remains. Who survives?
- A. 5
- B. 6
- C. 10
- D. 9
Correct answer: A. 5
For k = 2 the Josephus survivor is 2 times the number of people minus a power of two, here 2 * (10 - 8) + 1 = 5 when using the closed form. The recurrence gives the same 1-based answer.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many unordered pairs {x, y} of distinct integers from 1 to 20 have x + y divisible by 5?
- For "dcbadcba", among its rotations, which starting index i (0-based, the rotation s[i:] + s[:i]) gives the lexicographically smallest…
- What is the maximum nesting depth of parentheses in "(()(()))()"?
- How many distinct values does floor(n / 3) take as n ranges over 1 to 20 inclusive?
- What is the sum of an = n mod 7 for n from 1 to 20 inclusive?
- From [1, 2, 2, 3, 5, 6, 6], what is the maximum number of disjoint pairs where the two values differ by at most 1?