Cod sursa(job #518535)

Utilizator ciprianfFarcasanu Alexandru Ciprian ciprianf Data 1 ianuarie 2011 17:17:14
Problema Congr Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <stdio.h>
#include <algorithm>
#include <time.h>
#include <stdlib.h>
using namespace std;
#define NMAX 600010
int V[NMAX], ind[NMAX];
int n, S;
inline int modulo(int x){
	if(x > n) return x-n;
	if(x < 0) return x+n;
	return x;
}
int main(){
	freopen("congr.in", "r", stdin);
	freopen("congr.out", "w", stdout);
	scanf("%d", &n);
	
	for(int i = 1; i < 2*n; ++i){
		scanf("%d", &V[i]);
		V[i] %= n;
		ind[i] = i;
		if(i <= n) S = (S+V[i])%n;
	}
	int p1, p2;
	srand(time(NULL));
	while(S){
		p1 = 1 + rand()%n;
		p2 = n + 1 + rand()%(n-1);
		S = modulo(S - V[ind[p1]] + V[ind[p2]]);
		swap(ind[p1], ind[p2]);
	}
	for(int i = 1; i <= n; ++i)
		printf("%d ", ind[i]);
	return 0;
}