11380 - Chen Midterm1- Problem1   

Description

[Partial Judge Problem]

Problem description:

We define a Josephus game as follows:

1. There are n people , numbered as 1 to n, in a circle and arranged in clockwise.

2. The person with ID = 1 is the killer at the beginning of the game.

3. If the number of survivor is even :

     The killer will kill the person who is oppisite from himself .

     The person next to the victim in clockwise direction will be the new killer.

     Ex: If there are 4 people in the game , the 1st victim will be 3 .

          4 will become the new killer.

                     1(killer)                                                      1

              4                   2               ----->              4(killer)            2

                     3(victim)

4. If the number of survivor is odd :

    The killer will kill the person next to himself in counter-clockwise direction.

    The person next to the victim in counter-clockwise direction will be the new killer.

         Ex:

                         1                                                         1(killer)

           4(killer)          2(victim)       ----->            4

 

5. The winner is the one survive at the end of the game.

Judge language : C

Your task is to implement following functions  :

  1.  (Required) Node* createList(int n, Node*);
  2.  (Required) int solveJosephus(int numOfPeople , Node* head);
  3. (Optional) other functions you will need

Submit format:

#include <stdio.h>
#include <stdlib.h>
#include "function.h"

//------------------------------------------

/*Other functions*/

//------------------------------------------

int solveJosephus(int n , Node* head){

      /*your code here*/

}

Node* createList(int n , Node* head){

    /*your code here*/

}

Input

There are multiple lines in an input testcase .

Each line represents a Josephus game

Each line contains an integer indicates the number of people joining the josephus game.

The input format is determined by the judge code

You don't have to worry about it.

Output

Show the winner of each josephus game.

The output format is determined by the judge code.

You don't have to worry about it . 

Sample Input  Download

Sample Output  Download

Partial Judge Code

11380.c

Partial Judge Header

11380.h

Tags




Discuss