//--------------------------------------------------------------------------- #include int n,k; int *pos; //--------------------------------------------------------------------------- void generaCasos(int n,int k,int itera,FILE *output) { int i; fprintf(output,"%d %d\n",n,k); for(i = 1; i <= n; i++) { fprintf(output,"%d ",(i*itera)%n + 1); } } //--------------------------------------------------------------------------- void quickSort(int *array,int *indice,int lower,int higher) { int lo, hi, mid, t; lo = lower; hi = higher; mid = array[(lo+hi)/2]; do { while( array[lo] < mid ) lo++; while( array[hi] > mid ) hi--; if( lo <= hi ) { // Intercambiamos los extremos. t = array[lo]; array[lo] = array[hi]; array[hi] = t; // Intercambiamos los índices t = indice[lo]; indice[lo] = indice[hi]; indice[hi] = t; lo++; hi--; } } while (lo <= hi); if( hi > lower ) quickSort(array,indice,lower,hi); if( lo < higher ) quickSort(array,indice,lo,higher); } //--------------------------------------------------------------------------- void leeDatos(void) { int i; FILE *input = fopen("input.txt","r+t"); fscanf(input,"%d %d",&n,&k); pos = new int[n]; for(i = 0; i < n; i++) fscanf(input,"%d ",&pos[i]); fclose(input); } //--------------------------------------------------------------------------- int main(void) { FILE *output; int i; int *index; /* output = fopen("input8.txt","w+t"); generaCasos(11,90000,100,output); fclose(output); */ leeDatos(); index = new int[n]; for(i = 0; i < n-1; i++) { pos[i] = ( pos[i] + ((i+1)*k) )%n; index[i] = i+1; } pos[n-1] = n; index[n-1] = n; quickSort(pos,index,0,n-1); output = fopen("output.txt","w+t"); if( n == 1 ) fprintf(output,"DE FIESTA"); else if( pos[0] == pos[1] ) fprintf(output,"DE FIESTA"); else for(i = 0; i < n; i++) fprintf(output,"%d ",index[i]); delete[] pos; delete[] index; fclose(output); return 0; } //---------------------------------------------------------------------------