Loading

Codeforces Round #150 (Div. 2) A. Dividing Orange

原题链接

题目分析:

题意:把一个橘子分给\(k\)个人,保证每个人有\(n\)个橘子,同时还要保证每个人单独要某个编号的橘子的要求

这道题只需要把没被分走的橘子存到set里,然后分一个删一个

AC代码

#include <bits/stdc++.h>
using namespace std;

const int N = 40;
int a[N];
set<int> se;

int n, k;
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n * k; i++) se.insert(i);
    for(int i = 1; i <= k; i++) {
        cin >> a[i];
        se.erase(se.lower_bound(a[i]));
    }
    
    for(int w = 1; w <= k; w++ ) {
        cout << a[w] << ' ';
        for(int i = 1; i < n; i++) {
            auto t = se.begin();
            cout << *t << ' ';
            se.erase(t);
        }
        cout << '\n';
    }
    
    return 0;
}
posted @ 2021-03-12 20:00  Frank_Ou  阅读(42)  评论(0编辑  收藏  举报