问题描述:一堆小孩围成一个圈,从第一个小孩开始数,每数到第三个便把第三个孩子删去,数到只剩一个小孩为止,并求该孩子的具体编号。

解决办法

1.

package test;
public class Compare {
public static void main(String[] args) {
boolean[] array=new boolean[];
for(int i=;i<array.length;i++) {
array[i]=true;
}
int leftcount = ;
int countnum = ;
int index = ; while(leftcount > ) {
if(array[index]) {
countnum ++;
if(countnum == ) {
countnum = ;
array[index] = false;
leftcount--;
}
}
index ++;
if(index == ) {
index = ;
}
}
for(int i=;i<array.length;i++) {
if(array[i]) {
System.out.println(i);
}
}
} }

2.

package test;

public class Studentcircle {
public static void main(String[] args) {
makecircle b=new makecircle();
int countnum=;
student m=b.first;
while(b.count>) {
countnum++;
if(countnum==) {
countnum=;
b.delete(m);
}
m=m.right;
}
System.out.println(b.first.id);
} }
class student{
int id;
student left;
student right;
}
class makecircle{
int count=;
student first,last;
makecircle(int n){
for(int i=;i<n;i++) {
add();
}
}
void add() {
student x= new student();
x.id=count;
if(count<=) {
first=x;
last=x;
x.left=x;
x.right=x;
}else {
last.right=x;
x.left=last;
x.right=first;
first.left=x;
last=x;
}
count++;
}
void delete(student x) {
if(count<=) {
return;
}else if(count==) {
first=last=null;
}else {
x.left.right=x.right;
x.right.left=x.left; if(x==first) {
first=x.right;
}else if(x==last) {
last=x.left;
}
}
count --;
} }

最新文章

  1. ABP架构设计交流群-上海线下交流会的内容分享(有高清录像视频的链接)
  2. c# socket
  3. C#串口通讯实例
  4. 写在学AngularJS之前
  5. [BZOJ1116][Poi2008]LCO(并查集)
  6. 移动端bug总结
  7. word-break:break-all和word-wrap:break-word的区别
  8. lintcode:Subtree 子树
  9. CentOS Nginx+jdk+tomcat 环境搭建
  10. 移动web:翻页场景动画
  11. Hadoop化繁为简-从安装Linux到搭建集群环境
  12. 计算机网络之套接字SOCKET
  13. 未能加载文件或程序集“file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0
  14. swiper 自定义分页器的使用
  15. [Unity][安卓]Unity和Android Studio 3.0 交互通讯(1)Android Studio 3.0 设置
  16. hdu 1263 水果 【二维map】
  17. 黄聪:OTP动态密码_Java代码实现
  18. 使用Qt开发绘制多个设备的流量曲线图(附带项目图)
  19. java框架篇---hibernate(一对一)映射关系
  20. 【巷子】---json-server---基本使用

热门文章

  1. Java GC2
  2. Session establishment complete on server 2181, sessionid = 0x35fb853eb6f0004
  3. courator - create
  4. Java - 15 Java 正则表达式
  5. Heartbeat+DRBD+MFS高可用
  6. android:clipChildren属性,子布局超出父布局;
  7. call与apply简单介绍
  8. 深入Spring Boot:怎样排查 Cannot determine embedded database driver class for database type NONE
  9. 解决从客户端(Content=&quot;&lt;div&gt;&lt;p &gt;&lt;p&gt;12312...&quot;)中检测到有潜在危险的Request.Form 值。
  10. ES6入门声明