Exercise1_3_37
2016-02-05 20:18
253 查看
package chapterone; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Josephus { public static void main(String[] args) { Queue<Integer> queue = new LinkedList<Integer>(); System.out.println("start"); System.out.println("————————————————"); Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int M = scan.nextInt(); scan.close(); for (int i = 0; i < N; i++) { queue.add(Integer.valueOf(i)); } int k = 0; while (!queue.isEmpty()) { int x = queue.poll(); if ((++k) % M == 0) { System.out.print(x + " "); } else { queue.add(Integer.valueOf(x)); } } } }
相关文章推荐
- HDU3047带权并查集
- 算法_2:数值算法
- Cloud Design Patterns: Prescriptive Architecture Guidance for Cloud Applications 云设计模式:云应用的规范架构指导
- 队列
- Open Credit System
- 线索二叉树
- HDU 1247 Hat’s Words
- WM_PAINT消息详解,使用InvalidateRect或InvalidateRgn函数刻意产生WM_PAINT消息(WIN7里有变化,“调整视觉效果”,将“启用桌面组合”去掉)
- Scanf函数的输入问题
- NSWindow.setFrame的坑
- HTML5开发移动web应用——Sencha Touch篇(8)
- 自定义等高的cell(代码Autolayout)
- Android Studio之提高编译的效率
- Fill the Square
- Theano 逻辑回归教程 的注释
- Linux查看系统信息小命令
- HDU 1005.Number Sequence【用递归会超时】(2.5)
- HDU3501 Calculation 2(欧拉函数)
- 第一次在ubuntu配置apache+php+mysql环境运行laravel5.1
- 例题6-7 UVa122 Trees on the level(树&&队列BFS&&sscanf字符串转整数)