Mai intai trebuie sa te autentifici.
Cod sursa(job #497315)
| Utilizator | Data | 2 noiembrie 2010 09:13:13 | |
|---|---|---|---|
| Problema | Fractal | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <stdio.h>
FILE *f,*s;
int k,x,y,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); // Cadran 1
if(x>l&&y<=l) { z+=l*l; Rezolva(k-1,x-l,y); } // Cadran 2
if(x>l&&y>l) { z+2*l*l; Rezolva(k-1,x-l,y-l); } //Cadran 3
if(x<=l&&y>l) { z+=3*l*l; Rezolva(k-1,2*l-y+1,l-x+1); } //Cadran 4
}
int main()
{
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;
}
