Description
The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n, standing in circle every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give us the message about the incident. For example when n = 6 and m = 5 then the people will be executed in the order 5, 4, 6, 2, 3 and 1 will be saved.
Suppose that there are k good guys and k bad guys. In the circle the first k are good guys and the last k bad guys. You have to determine such minimal m that all the bad guys will be executed before the first good guy.

Input
The input file consists of separate lines containing k. The last line in the input file contains 0. You can suppose that 0 < k < 14.

Output
The output file will consist of separate lines containing m corresponding to k in the input file.
大意就是:给出k个好孩子和k个坏孩子,好孩子在前,坏孩子在后。然后围成一圈,从第一个开始报数,报到m的退出,求最小的的m满足前k个出局的孩子都是坏孩子。
对于约瑟夫环问题大家的第一影响应该是模拟,数组和链表都行,但是这里如果用不加优化的模拟的话,超时是不可避免的,对于k=13,m是200多万,一个一个枚举,会死人的。。。不过用数组模拟时有个优化,就是m对剩下的人数先取模,也就是说剩下的人数的整数倍对最后的结果不影响。这里可以剪掉很多。还有就是得先把这13个结果算出来,不然还是会超时,因为case居多。。。
下面给出官方的代码(建议先自己想)
官方