1617 - I2P(II)2019_Yang_Lab2 Scoreboard

Time

2019/03/08 13:30:00 2019/03/08 15:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12166 Joslimes Problem Using Doubly Linked List

12166 - Joslimes Problem Using Doubly Linked List   

Description

This is PARTIAL JUDGE
“Josephus Problem” and its variations are introduced in class many times. However, things are a little bit different this time. After the Jewish soldiers got executed in the original problem, one of them got reincarnated(轉生) as a slime. (The link has nothing to do with this problem, we suggest you click this after the exam) In honor of the great mathematician Josephus, the slime introduced the Josephus Problem to his(?) slime friends.

There are n slimes in a circle, numbered from 1 to n. Since slimes are monsters, when a slime got shot, it will reproduce k slimes on its counterclockwise side ( the newly reproduced slimes have the same number as the original one). The following is the slime’s version of Josephus Problem (namely “Joslimes Problem”):

  • The first slime to have the gun is slime No. 1, and they pass a gun with n bullets in clockwise direction.
  • Count from the slime holding the gun for b times in clockwise order, where b is the number of remaining bullets. After that, the last counted slime has the gun and shoots itself.
  • After n shots, there are no remaining bullets. The shooting process terminates.

Your problem is to output how many slimes of each number there are finally.
Refer to sample IO for example.
You’re asked to solve this problem using a circular linked list.
You will be provided with main.c and function.h, and you need to implement function.c.
Note: Slimes don’t like memory leaks.

Note : For the first time you should count the slime with the gun. After that you don't need to do it anymore.

Input

Input contains multiple testcases.
The first line contains a single integer T. There are T testcases in total.
Each testcase occupies a single line, consisting of two integers n, k, meaning that there are n slimes at first and k more slimes will be reproduced after a slime get shot (i.e. after a slime get shot, there will be k+1 slimes).

  • 1 <= T <= 10
  • 1 <= n,k <= 1000

Output

For each testcase, output n integers in a line, where the ith integer stands for the number of remaining number-i slimes .

These integers are separated with a space. No space at the end of the line.


Sample IO: there is 1 testcase, with 3 slimes and k = 3

  • Initially, 1 2 3 stands in a circle, with three remaining bullets.
  • Counting from 1 for three times, 3 is the last slime. It shoots itself, reproducing k slimes in its counterclockwise side, resulting in 1 2 3 3 3 “3” (Note that the original slime still has the gun). There are two remaining bullets(As shown below).
  • Counting for two times, 2 is the last slime, and it reproduces k slimes, resulting in 1 2 2 2 “2” 3 3 3 3. There is one remaining bullet.
  • Counting for one time, 3 is the last slime, resulting in 1 2 2 2 2 3 3 3 “3” 3 3 3.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

12166.c

Partial Judge Header

12166.h

Tags




Discuss