约瑟夫环问题
2015-10-11 15:48
169 查看
/* *约瑟夫环问题 * 抱1 2 3 */ import java.util.*; public class Yuan{ public static void main(String[] args) throws Exception{ Scanner input = new Scanner(System.in); int p = input.nextInt(); System.out.println(leftPerson(p)); } public static int leftPerson(int n) throws Exception { boolean[] per = new boolean ; for (int i = 0; i < per.length; i++) { per[i] = true; } int t = 0, len = per.length; while (len > 1) { for (int i = 0; i < per.length; i++) { if (per[i]) { t++; if (t == 3) { t = 0; per[i] = false; len--; } } } } int a = 0; for(int j = 0;j<per.length;j++){ if(per[j]=true){ a = j; } } return a; } }
相关文章推荐
- 程序员书单_云计算篇
- MongoDB安装
- 数组
- 【Linux】vim中高频使用指令总结--->使vim用起来更加得心应手
- 【设计模式】——六原则(一)
- 转载js入门须知
- 找路径
- 10.11 函数
- hdu 5038 Grade(分级)
- android实现gif动态图的使用
- 成段改A为B更新区间求和 hdu 1698 Just a Hook
- android实现gif动态图的使用
- PyCharm 配置&&操作
- 程序员书单_云计算篇
- Android中shape的使用
- 找路径 带障碍
- 一个校园实验室的纳新试题(试题整理)
- OpenCV—利用回调函数实现返回鼠标点击位置的坐标和灰度值
- 注解
- xcode 错误提示: LaunchScreen.xib: Line 20: EntityRef: expecting ';'