解答

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Created by feng on 17-9-4.
 */
public class CCF_201609_2 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner = new Scanner(new File("data"));
//        Scanner scanner = new Scanner(System.in);
        int[] ticket = new int[100];
        int[] shengyu = new int[20];//标记数组当前排剩余多少作为
        for (int i = 0; i < 20; i++) {
            shengyu[i] = 5;
        }
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int cmd = scanner.nextInt();
            if (cmd > 5){//剪枝操作,如果指令大于5就不需要遍历有没有连坐
                int  j = 0;
                while (cmd > 0){
                    if (ticket[j] != 1){
                        ticket[j] = 1;
                        System.out.print( (j+1) + " ");
                        cmd--;
                        shengyu[j/5]--;
                    }
                    i++;
                }
                System.out.println();
                continue;
            }
            for (int k = 0; k < 20; k++) {//遍历
                if (shengyu[k] >= cmd){
                    shengyu[k] -= cmd;
                    int j = k*5 ;
                    while (cmd > 0){
                        if (ticket[j] != 1){
                            ticket[j] = 1;
                            System.out.print( (j+1) + " ");
                            cmd--;
                        }
                        j++;
                    }
                }
            }

            int  j = 0;
            while (cmd > 0){//遍历不出来的话挨个放进去进去
                if (ticket[j] != 1){
                    ticket[j] = 1;
                    System.out.print( (j+1) + " ");
                    cmd--;
                    shengyu[j/5]--;
                }
                i++;
            }
            System.out.println();
        }
    }
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Created by feng on 17-9-4.
 */
public class Main{
    public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner = new Scanner(System.in);
        int[] ticket = new int[100];
        int[] shengyu = new int[20];//标记数组当前排剩余多少作为
        for (int i = 0; i < 20; i++) {
            shengyu[i] = 5;
        }
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int cmd = scanner.nextInt();
            if (cmd > 5){//剪枝操作,如果指令大于5就不需要遍历有没有连坐
                int  j = 0;
                while (cmd > 0){
                    if (ticket[j] != 1){
                        ticket[j] = 1;
                        System.out.print( (j+1) + " ");
                        cmd--;
                        shengyu[j/5]--;
                    }
                    i++;
                }
                System.out.println();
                continue;
            }
            for (int k = 0; k < 20; k++) {//遍历
                if (shengyu[k] >= cmd){
                    shengyu[k] -= cmd;
                    int j = k*5 ;
                    while (cmd > 0){
                        if (ticket[j] != 1){
                            ticket[j] = 1;
                            System.out.print( (j+1) + " ");
                            cmd--;
                        }
                        j++;
                    }
                }
            }

            int  j = 0;
            while (cmd > 0){//遍历不出来的话挨个放进去进去
                if (ticket[j] != 1){
                    ticket[j] = 1;
                    System.out.print( (j+1) + " ");
                    cmd--;
                    shengyu[j/5]--;
                }
                i++;
            }
            System.out.println();
        }
    }
}