算法(Algorithms)第4版 练习 1.3.37
2017-03-08 16:48
429 查看
package com.qiusongde.creative; import com.qiusongde.Queue; import edu.princeton.cs.algs4.StdOut; public class Josephus { public static void main(String[] args) { int n = Integer.parseInt(args[0]); int m = Integer.parseInt(args[1]); Queue<Integer> queue = new Queue<Integer>(); for(int i = 0; i < n; i++) { queue.enqueue(i); } while(!queue.isEmpty()) { for(int i = 0; i < (m - 1); i++) { queue.enqueue(queue.dequeue()); } StdOut.print(queue.dequeue() + " "); } } }
测试1:
1 3 5 0 4 2 6
测试2:
2 6 5 1 3 0 4
相关文章推荐
- 算法(Algorithms)第4版 练习 2.2.11(最终)
- 算法(Algorithms)第4版 练习 2.2.23
- 算法(Algorithms)第4版 练习 1.3.27 1.3.28
- 算法(Algorithms)第4版 练习 1.3.15
- 算法(Algorithms)第4版 练习 1.4.6
- 算法(Algorithms)第4版 练习 1.5.9
- 算法(Algorithms)第4版 练习 2.1.24
- 算法(Algorithms)第4版 练习 1.3.23 1.3.22
- 算法(Algorithms)第4版 练习 2.1.1
- 算法(Algorithms)第4版 练习 1.3.21
- 算法(Algorithms)第4版 练习 1.3.14
- 算法(Algorithms)第4版 练习 1.3.6
- 算法(Algorithms)第4版 练习 1.5.22
- 算法(Algorithms)第4版 练习 1.3.26
- 算法(Algorithms)第4版 练习 1.3.20
- 算法(Algorithms)第4版 练习 1.3.13
- 算法(Algorithms)第4版 练习 1.3.5
- 算法(Algorithms)第4版 练习 1.5.10
- 算法(Algorithms)第4版 练习 2.2.11(3)
- 算法(Algorithms)第4版 练习 2.2.26