Cod sursa(job #1239445)

Utilizator enedumitruene dumitru enedumitru Data 9 octombrie 2014 00:37:40
Problema Congr Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<fstream>
//#include<ctime>
#define DIM 8192
using namespace std;
ofstream g("congr.out");
int p,i,j,poz,a[600000],b[600000];
long long s;
char x[DIM];
void cit(int &nr)
{   nr=0;
    while(x[poz]<'0'||x[poz]>'9')     
        if(++poz==DIM) fread(x,1,DIM,stdin),poz=0;
    while('0'<=x[poz]&&x[poz]<='9')
    {   nr=nr*10+x[poz]-'0';
        if(++poz==DIM) fread(x,1,DIM,stdin),poz=0;               
    }     
}
int main () 
{   freopen("congr.in","r",stdin);
	cit(p);
	for(i=1;i<2*p;++i)
    {   cit(a[i]);
        if(i<=p) s+=a[i];
        b[i]=i;
    }
	//srand(time(0));
    while(s%p) 
	{   i=1+rand()%p;
        j=1+p+rand()%(p-1);
        s=s+a[b[j]]-a[b[i]];
        swap(b[i],b[j]);
    }
    for(i=1;i<=p;i++) g<<b[i]<<' ';
    g<<'\n'; g.close(); return 0;
}