Cod sursa(job #655554)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 2 ianuarie 2012 20:39:13
Problema Congr Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <cstdio>
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<<i<<" ";
            ok=1;
        }
        if (ok==1) break;
        for(i=1; i<=2*p-1; i++) mark[i]=0;
    }
g<<'\n';
    f.close();
    g.close();
    return 0;
}