Pagini recente » Cod sursa (job #154576) | Cod sursa (job #392768) | Cod sursa (job #1993318) | Istoria paginii runda/oni_clasa_9 | Cod sursa (job #274779)
Cod sursa(job #274779)
#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;
}