Cod sursa(job #2904899)

Utilizator Albert_GAlbert G Albert_G Data 18 mai 2022 16:09:00
Problema Lacate Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <vector>

std::ifstream in("lacate.in");
std::ofstream out("lacate.out");

constexpr int N = 257;
std::vector<int> chei[N];

void imparteChei(int n, int nrL){
    int cnt = 0;
    for(int key=1; key<=nrL; ++key){
        cnt %= n;
        if(cnt == n-1){
            chei[n-1].push_back(key);
            chei[0].push_back(key);
            cnt = 1;
        }
        else{
            chei[cnt].push_back(key);
            chei[cnt+1].push_back(key);
            cnt += 2;
        }
    }
}

int main(){
    int n;
    in >> n;
    in.close();
    int nrLacate = n * (n-1) / 2; // combinari de n luate cate n-2 (adica de la fiecare n-2 oameni vor lipsi 2 chei)
    imparteChei(n, nrLacate);
    int nrChei = chei[0].size();
    out << nrLacate << ' ' << nrChei << '\n';
    for(int i=0; i<n; ++i){
        for(auto key : chei[i]){
            out << key << ' ';
        }
        out << '\n';
    }
    out.close();
    return 0;
}