[Java] 纯文本查看 复制代码
import java.util.Scanner;
public class Demo {
public static void main(String[] args){
fun02();
}
public static void fun02() {
boolean[][] sets = new boolean[20][5];
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-- > 0) {
int p = sc.nextInt();
int set[] = new int[p],cnt=0;
boolean _ok = false;
out:for(int i = 0 ; i < sets.length ; i++) {
for(int j = 0 ; j < sets.length ; j++) {
if( sets[j] == false ) {
if( sets.length - j >= p ) {
_ok = true;
int t = p;
while( t-- > 0 ) {
set[cnt++] = i * sets.length + j + 1;
sets[j++] = true;
}
break out;
}
}
}
}
if( !_ok ) {
int t = p;
out:for(int i = 0 ; i < sets.length ; i++) {
for(int j = 0 ; j < sets.length ; j++) {
if(t > 0 && sets[j] == false ) {
sets[j] = true;
set[cnt++] = i * sets.length + j + 1;
t--;
if( t <= 0 )
break out;
}
}
}
}
for(int i : set) {
System.out.print(i + " ");
}System.out.println();
}
}
}