Pagini recente » Cod sursa (job #18142) | Cod sursa (job #2828715) | Cod sursa (job #2238160) | Cod sursa (job #1483027) | Cod sursa (job #497317)
Cod sursa(job #497317)
#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;
}