Cod sursa(job #999181)

Utilizator harababurelPuscas Sergiu harababurel Data 19 septembrie 2013 17:32:51
Problema Congr Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <vector>
#define nmax 300005
using namespace std;

vector <int> used, unused;

int v[nmax];
int p, s = 0, x, y, aux;

int getRand(int n) { return rand() % n; }

int main() {
    srand((unsigned)time(0));
    ifstream f("congr.in");
    ofstream g("congr.out");

    f>>p;
    for(int i=1; i<2*p; i++) {
        f>>v[i];
        //v[i] %= p;
    }

    for(int i=1; i<=p; i++) {
        used.push_back(i);
        s += v[i];
    }
    for(int i=p+1; i<2*p; i++) unused.push_back(i);

    while(s % p != 0) {
        x = getRand(unused.size());
        y = getRand(used.size());

        s = s - v[used[y]] + v[unused[x]];

        aux = used[y];
        used[y] = unused[x];
        unused[x] = aux;
    }

    for(int i=0; i<used.size(); i++)
        g<<used[i]<<" ";
    g<<"\n";

    return 0;
}