public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
for(int k=0;k<n;k++) {
Queue<Integer> q=new LinkedList<>();
int m=sc.nextInt();
for(int i=0;i<m;i++) {
q.add(i+1);
}
// System.out.println(q);
while(!q.isEmpty()) {
for(int i=1;i<3;i++) {
q.add(q.peek());
q.poll();
}
if(q.size()!=1) {
System.out.print(q.peek()+" ");
q.poll();
}else {
System.out.println(q.peek());
q.poll();
}
}
}
}
约瑟夫问题--围圈报数---循环队列的使用
于 2023-03-12 15:58:06 首次发布