| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1817 人关注过本帖
标题:解决问题,给答案,不要随便应付,谢谢。
只看楼主 加入收藏
zflovedota
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2017-6-12
结帖率:50%
收藏
 问题点数:0 回复次数:2 
解决问题,给答案,不要随便应付,谢谢。
题目描述
Do 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?


输入
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.


输出
For each test case, output a line containing m integers, the people executed in the q[i]-th round.


样例输入
2 1 0 1 2 3
1
41 5 1 1 0 2
1 2 3 4 40

样例输出
1
2 4 6 8 35

搜索更多相关主题的帖子: direction becoming waiting freedom person 
2017-06-13 08:54
peng880610
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:128
专家分:123
注 册:2017-3-29
收藏
得分:0 
你这个全英文的,这不是为难大家吗?
2017-06-14 00:27
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10527
专家分:42899
注 册:2014-5-20
收藏
得分:0 
什么问题?
2017-06-14 05:37
快速回复:解决问题,给答案,不要随便应付,谢谢。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016703 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved