Cod sursa(job #497317)

Utilizator Anamaria20Cotirlea Anamaria Anamaria20 Data 2 noiembrie 2010 09:20:05
Problema Fractal Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <stdio.h>

FILE *f,*s;

int z;

void Rezolva(int k,int x, int y)
{
	if(k==0) return; 
    
	int l=(1<<(k-1)); 
    
	if(x<=l && y<=l) Rezolva(k-1,y,x); 
    
	if(x>l && y<=l) { z+=l*l; Rezolva(k-1,x-l,y); } 
    
	if(x>l && y>l) { z+=2*l*l; Rezolva(k-1,x-l,y-l); } 
    
	if(x<=l && y>l) { z+=3*l*l; Rezolva(k-1,2*l-y+1,l-x+1); } 
}

int main()
{
	int k,x,y;
	
	f=fopen("fractal.in","r");
	s=fopen("fractal.out","w");
	
	fscanf(f,"%d %d %d",&k,&x,&y);
	
	Rezolva(k,x,y);
	
	fprintf(s,"%d",z);
	
	fclose(s);
	
	return 0;
}