http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1149
Josephus ProblemDo you know the famous Josephus Problem? There are n people standing in a circle waiting to be executed. The counting out begins at the first people in the circle and proceeds around the circle in the counterclockwise direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. In traditional Josephus Problem, the number of people skipped in each round is fixed, so it's easy to find the people executed in the i-th round. However, in this problem, the number of people skipped in each round is generated by a pseudorandom number generator: x[i+1] = (x[i] * A + B) % M. Can you still find the people executed in the i-th round? Input There are multiple test cases. The first line of each test cases contains six integers 2 ≤ n ≤ 100000, 0 ≤ m ≤ 100000, 0 ≤ x[1], A, B < M ≤ 100000. The second line contains m integers 1 ≤ q[i] < n. Output For each test case, output a line containing m integers, the people executed in the q[i]-th round. Sample Input 2 1 0 1 2 3
1
41 5 1 1 0 2
1 2 3 4 40
Sample Output 1
2 4 6 8 35
#include<iostream>
|
湘潭市赛 Josephus Problem 线段树
最新推荐文章于 2019-06-27 09:25:09 发布