首页 > ACM题库 > HDU-杭电 > HDU 1443 Joseph-模拟-[解题报告] C++
2013
12-10

HDU 1443 Joseph-模拟-[解题报告] C++

Joseph

问题描述 :

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.

输入:

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.

输出:

The output file will consist of separate lines containing m corresponding to k in the input file.

样例输入:

3
4
0

样例输出:

5
30


解题报告转自:http://www.cnblogs.com/anderson0/archive/2011/05/08/2040356.html


  1. 第二种想法,我想来好久,为啥需要一个newhead,发现是把最后一个节点一直返回到嘴上面这层函数。厉害,这道题之前没样子想过。

  2. 站长好。我是一个准备创业的互联网小白,我们打算做一个有关国*际*游*学的平台。手上也有了一些境外资源。现阶段的团队现在没有cto.原意出让一些管理股寻找一个靠谱的技术专家做合伙人, 不知道是不是能得到您的帮助。发个帖子或者其他方式。期待您的回应。可以加我微信tianxielemon聊聊。