Cod sursa(job #132652)

Utilizator razvi9Jurca Razvan razvi9 Data 6 februarie 2008 12:16:19
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include<stdio.h>
#include<math.h>
int i,j,k;
int poz(int i,int j,int k)
{
	if(k==1) 
		if(i==1)
			if(j==1) return 0;
			else
				return 3;
		else
			if(j==1) return 1;
			else return 2;
	int size=1<<(k-1);
	int cost,i1,j1;
	if(i>size) 
		if(j>size){
			cost=size*size*2;
			i1=i-size;
			j1=j-size;
			cost+=poz(i1,j1,k-1);}
		else{
			cost=size*size;
			i1=i-size;
			j1=j;
			cost+=poz(i1,j1,k-1);}
	else
		if(j>size){
			cost=3*size*size;
			j1=j-size;
			i1=size-j1+1;
			j1=i;
			cost+=size*size-poz(i1,j1,k-1)-1;}
		else{
			cost=0;
			i1=j;
			j1=size-i+1;
			cost+=size*size-poz(i1,j1,k-1)-1;}
	return cost;
}

int main()
{freopen("fractal.in","r",stdin);
 freopen("fractal.out","w",stdout);
 scanf("%d %d %d",&k,&j,&i);
 printf("%d",poz(i,j,k));
 fclose(stdout);
 return 0;}