zoukankan      html  css  js  c++  java
  • 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 << '
    ';
        }
        
        return 0;
    }
    
  • 相关阅读:
    mysql基本用法
    linux基本指令
    servlet的生命周期
    day 15 笔记
    day 14 作业
    考试二
    day 14
    day 12 zuoye
    day 13
    day 12
  • 原文地址:https://www.cnblogs.com/FrankOu/p/14526102.html
Copyright © 2011-2022 走看看