kingofpineapples's blog

By kingofpineapples, history, 2 years ago, In English

I was looking at the Josephus Problem II in the CSES problem set, and couldn't find a c++ solution that didn't use ordered_set, which is not in the standard library. This made me wonder if I need to learn about other libraries to get good at cp. Any input appreciated.

Also if someone knows how to solve the Josephus Problem II only using the standard library please outline it for me ty

  • Vote: I like it
  • +8
  • Vote: I do not like it

»
2 years ago, # |
  Vote: I like it +8 Vote: I do not like it

my code here.

You essentially brute force the algorithm by finding the next person by literally locating the k'th person to the right.

The ordered set is needed in some solutions for querying "kth largest in a set of integers". Such queries can also be done by walking on segtrees as well.

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

I have solved it using binary search & BIT.

code