Cod sursa(job #655545)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 2 ianuarie 2012 20:31:52
Problema Congr Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
ifstream f("congr.in");
ofstream g("congr.out");
int p,i,t,poz,mark[600005],v[600005],s,q,ok;
int main()
{
    f>>p;
    srand(time(0));
    for(i=1; i<=2*p-1; i++) f>>v[i];

    for(;;)
    {
        s=0,q=0;
        for(; q<p;)
        {
            poz=rand()%(2*p-1)+1;
            if (mark[poz]==0) q++,mark[poz]=1;
        }

        for(i=1; i<=2*p-1; i++)
            if (mark[i]==1)s+=v[i];

        if (s%p==0)
        {
            for(i=1; i<=2*p-1; i++)
                if (mark[i]==1) g<<v[i]<<" ";
            ok=1;
        }
        if (ok==1) break;
        for(i=1; i<=2*p-1; i++) mark[i]=0;
    }

    f.close();
    g.close();
    return 0;
}