Cod sursa(job #719275)

Utilizator deneoAdrian Craciun deneo Data 21 martie 2012 17:57:18
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

#define lung 100100

ifstream fin("copii2.in");
ofstream fout("copii2.out");

int rez, n, k, f[lung];
vector<int> sol[lung];


int main() {
    long long i, j, t, echipe;
    fin >> n >> k;
    for (rez = 1, i = 1; i < n; ++rez, i *= k);
    --rez;

    fout << rez << "\n";

    for (i = 1; i <= n; ++i)
        f[i] = i;

    for (i = 1; i <= rez; ++i) {
        echipe = 0;
        for (j = 1; j <= n; ++j) {
            sol[f[j] % k].push_back(j);
            f[j] /= k;
        }

        for (j = 0; j < k; ++j)
            if (!sol[j].empty())
                ++echipe;
        fout << echipe << "\n";

        for(j = 0; j < echipe; ++j) {
            fout << sol[j].size() << " ";
            for (t = 0; t < sol[j].size(); ++t)
                fout << sol[j][t] << " ";
            fout << "\n";
            sol[j].resize(0);
        }
    }
    fout.close();
    return 0;
}