Cod sursa(job #274779)

Utilizator brancoCristian Achim branco Data 9 martie 2009 23:12:31
Problema Order Scor 25
Compilator c Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <stdio.h>
#include <stdlib.h>

#define N 30050

int n , ind , i;

unsigned long children[N/32+1]; // bit 0 child present 1 child removed

int child_not_out(int ind){
 int byte=ind/32;
 int offset=ind%32;
 if((children[byte]>>offset & ((unsigned long) 1)) != ((unsigned long)0)){
  return 0;
 }
 return 1;
}

void remove_child(int index){
 int byte=ind/32;
 int offset=ind%32;
 children[byte]|=((unsigned long)1) << offset;
}

void next_index(int jumps){
 int k=0;
 while(k<jumps){
  ind++;
  if(ind == n) ind=0;
 
  if(child_not_out(ind)){
   k++;
  }
 }

 remove_child(ind);
}

int main(){

 FILE *f=fopen("order.in","r");
 fscanf(f , "%d" , &n);
 fclose(f);

 f=fopen("order.out" , "w");
 for(i=1 ; i<=n;i++){
  next_index(i);
  fprintf(f , "%d " , ind+1);
 }
 fclose(f);

 return 0;
}