ccf201609-2

#include
using namespace std;
bool visited[1005];
int main(){
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        int t;
        cin >> t;
        bool flag = false;
        for(int j = 0;j < 20;j++){

            int index = -1;
            for(int k = 5*j + 1;k <= 5*j + 5;k++){
                if(!visited[k]){
                    index = k;
                    break;
                }
            }
            if(index == -1) continue;
            if(index + t - 1 <= 5*j + 5 && !visited[index + t - 1]){
                flag = true;
                for(int k = 0;k < t;k++){
                    visited[index+k] = 1;
                    cout << index + k;
                    if(k != t-1) cout << " ";
                    else cout << endl;
                }
                break;
            }
        }
        if(!flag){
            int cnt = 0;
            for(int j = 1;j <= 100;j++){
                if(!visited[j]){
                    visited[j] = 1;
                    cout << j;
                    cnt++;
                    if(cnt == t){
                        cout << endl;break;
                    }
                    cout << " ";
                }
            }
        }
    }


}

你可能感兴趣的:(ccf试题)