Pagini recente » Cod sursa (job #2020692) | Cod sursa (job #2003083) | Cod sursa (job #1768543) | Cod sursa (job #2147968) | Cod sursa (job #466933)
Cod sursa(job #466933)
# include <cstdio>
# include <stdlib.h>
# include <time.h>
using namespace std;
# define FIN "congr.in"
# define FOUT "congr.out"
# define MAX_N 300005
int P, i, j, s, aux;
int A[MAX_N << 1];
int Ind[2][MAX_N];
int main() {
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
srand(time(0));
scanf("%d", &P);
for (i = 1; i < P << 1; ++i) {
scanf("%d", &A[i]);
i <= P ? Ind[0][i] = i, s = (s + A[i]) % P : Ind[1][i - P] = i;
}
while (s) {
i = rand() % P + 1;
j = rand() % (P - 1) + 1;
s = (s + A[Ind[1][j]] % P + P - A[Ind[0][i]] % P) % P;
aux = Ind[0][i];
Ind[0][i] = Ind[1][j];
Ind[1][j] = aux;
}
for (i = 1; i <= P; ++i) printf("%d ", Ind[0][i]);
return 0;
}