Cod sursa(job #655562)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 2 ianuarie 2012 21:03:25
Problema Congr Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 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,v[600005],poz[600005],s,q,ok,p1,p2;
int main()
{
    f>>p;
    srand(time(0));
    for(i=1; i<=2*p-1; i++) f>>v[i];

    for(i=1; i<=p; i++) s+=v[i];

    for(i=1; i<=2*p-1; i++) poz[i]=i;

    for(; s%p!=0;)
    {
     p1=rand()%p+1,p2=2*p-1-(rand()%p+1)+1;
     s-=v[p1]+v[p2];
     swap(v[p1],v[p2]);
     swap(poz[p1],poz[p2]);
    }
for(i=1;i<=p;i++)g<<poz[i]<<" ";
    f.close();
    g.close();
    return 0;
}