Cod sursa(job #466933)

Utilizator Pepelea_FlaviuFlaviu Pepelea Pepelea_Flaviu Data 27 iunie 2010 22:38:34
Problema Congr Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
# 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;
    }