Pagini recente » Cod sursa (job #910479) | Cod sursa (job #1327141) | Cod sursa (job #2492125) | Cod sursa (job #1092662) | Cod sursa (job #929803)
Cod sursa(job #929803)
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#define N 600010
using namespace std;
int p,i,x,y,aux;
int A[N],R[N];
int VIZ[N];
int s;
FILE *f,*g;
void generate_random()
{
for (i=1;i<=p;++i)
{
x=rand()%p+1;
while (VIZ[x]==1)
x=rand()%p+1;
VIZ[x]=1;
R[i]=x;
}
}
int main()
{
f=fopen("congr.in","r");
g=fopen("congr.out","w");
fscanf(f,"%d",&p);
for (i=1;i<=2*p-1;++i)
fscanf(f,"%d",&A[i]);
generate_random();
s=0;
for (i=1;i<=p;++i)
s+=A[R[i]];
while (s%p!=0)
{
x=rand()%p+1;
y=rand()%(p-1)+p+1;
s=s+(A[y]-A[x]);
aux=R[x];
R[x]=R[y];
R[y]=aux;
}
for (i=1;i<=p;++i)
fprintf(g,"%d ",R[i]);
fclose(f);
fclose(g);
return 0;
}