11845 - Josephus_0   

Description

Based on the original Josephus Problem introduced in class, an additional rule of this problem is to change

direction of counting after killing a person. 

For example, there are 8 people, numbered 1 to 8, in a circle and arranged in clockwise. 

The step to kill in each round is incrementing by 1 and starting from 2 steps. 

Here's the example:

1, 2 (kill 2, change the direction to counter-clockwise)

1, 8, 7 (kill 7, change the direction to clockwise)

8, 1, 3, 4 (kill 4, change the direction to counter-clockwise)

3, 1, 8, 6, 5 (kill 5, change the direction to clockwise)

6, 8, 1, 3, 6, 8 (kill 8, change the direction to clockwise)

6, 3, 1, 6, 3, 1, 6 (kill 6, change the direction to counter-clockwise)

1, 3, 1, 3, 1, 3, 1, 3 (kill 3, change the direction to clockwise)

So the person numbered 1 is the survivor.

 

You're asked to solve this problem using circular linked list.

You will be provided with main.c and function.h, and you need to implement function.c.

Notice: There are several testcases with time limits.

Input

Multiple lines with each line representing the length of the sequence

Output

Each line represents the survivor number.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11845.c

Partial Judge Header

11845.h

Tags




Discuss