Cod sursa(job #1345589)

Utilizator BLz0rDospra Cristian BLz0r Data 17 februarie 2015 19:04:56
Problema Congr Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
 
#define Nmax 600002

FILE *f = fopen ( "congr.in" , "r" );
FILE *g = fopen ( "congr.out" , "w" );
 
int v[Nmax], sol[Nmax];
 
int main(){
    int N, x, y;
    long long S = 0;
 
    fscanf ( f, "%d", &N );
 
    srand (time (NULL));
 
    for ( int i = 1; i < 2 * N; ++i ){
        fscanf ( f,"%d", &v[i] );
        sol[i] = i;
        if ( i <= N )
            S += v[i];
    }
 
    while ( S % N ){
        x = 1 + rand () % N;
        y = N + 1 + rand () % (N - 1);
		
        S = S - v[x] + v[y];
        swap ( sol[x], sol[y] );
        swap ( v[x], v[y] );
    }
 
    for ( int i = 1; i <= N; ++i )
        fprintf ( g, "%d ", sol[i] );
 
    return 0;
}