算法Sedgewick第四版-第1章基础-017一约瑟夫问题(Josephus Problem)
2016-04-19 18:01
162 查看
/************************************************************************* * * Josephus problem * * % java Ex_1_3_37 7 2 * 1 3 5 0 4 2 6 * *************************************************************************/ public class Ex_1_3_37 { public static void main(String[] args) { int n = Integer.parseInt(args[0]), m = Integer.parseInt(args[1]); Queue<Integer> q = new Queue<Integer>(); for (int i = 0; i < n; i++) q.enqueue(new Integer(i)); int k = 0; while (!q.isEmpty()) { int x = q.dequeue(); if (++k % m == 0) StdOut.print(x + " "); else q.enqueue(x); } StdOut.println(); } }
相关文章推荐
- 深入理解Tornado——一个异步web服务器
- 汉化资料
- linux 常见问题大全
- 对齐函数:ALIGN()
- union和union all的区别
- JVM虚拟机性能监测与故障处理工具简单介绍
- superclass.constructor.call(this,config),参数问题 [
- zoj--3935--2016(暴力模拟)(数学)
- label和input垂直居中
- java面向对象三大特征之继承
- centos 系统 下载valgrind及其使用
- maven相关
- PostgreSQL之Union语句
- 【技术干货】驻云前端工程师带你初步了解chrome插件的开发
- 用于Linq的去重 Distinct
- 1. 服务器快捷访问
- Trace和Debug主要用法
- iOS 图形处理 Core Graphics Quartz2D 教程
- php 中 cookie 夸二级域名测试 共享数据
- vert.x core vert.x的核心是一个java api的集合