DSTJZ


私信TA

用户名:dotcpp0721777

访问量:5588

签 名:

天下难事,必作于易;天下大事,必作于细。

等  级
排  名 48
经  验 11333
参赛次数 13
文章发表 322
年  龄 18
在职情况 学生
学  校 狗熊岭23届毕业生
专  业

  自我简介:

TA的其他文章

java--study||O.o
浏览:29
java--study||O.o
浏览:28
java--study||O.o
浏览:35

模拟
参考代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.List;

public class Main{
	static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	static StreamTokenizer in = new StreamTokenizer(reader);
	static int STnextInt() throws IOException{
		in.nextToken();
		return (int)in.nval;
	}
	public static void main(String[] args) throws IOException{
		int n = STnextInt();
		int k = STnextInt();
		boolean[] vis = new boolean[n];
		int cnt = n;
		int index = 0;
		List<Integer> res = new ArrayList<>();
		while(cnt > 0){
			int num = 1;
			// 这里num只是帮忙计数,1~k
			while(num < k) {
				num++;
				index = (index + 1) % n;
				while(vis[index]) {
					index = (index + 1) % n;
				}
			}
			vis[index] = true; 
			res.add(index + 1);
			cnt--;
			while(cnt > 0 && vis[index]) {
				index = (index + 1) % n;
			}
		}
		for(int x: res) {
			System.out.print(x + " ");
		}
	}
}


 

0.0分

0 人评分

  评论区