Pagini recente » Cod sursa (job #3222932) | Cod sursa (job #363776) | Cod sursa (job #3244604) | Cod sursa (job #3212878) | Cod sursa (job #176603)
Cod sursa(job #176603)
//Fractal 2008
#include <fstream>
using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int fractal(int x,int y,int p){
int fract=0;
if ((x==y&&x==1)||p==1) return 0;
else
if (x<=p/2){
if (y<=p/2){
fract=fractal(y,p/2-x,p/2);
return fract;
}
if (y>p/2){
fract=fractal(x,y-p/2,p/2);
return (p/2)*(p/2)+fract;
}
} else
{
if (y>p/2)
{
fract=fractal(x-p/2,y-p/2,p/2);
return 2*(p/2)*(p/2)+fract;
}
if (y<=p/2)
{
fract=fractal(p/2-y+1,p-x+1,p/2);
return 3*(p/2)*(p/2)+fract;
}
}
}
int main(){
int x,y,p,k;
fin>>k>>x>>y;
p=1<<k;
fout<<fractal(x,y,p);
fout.close();
return 0;
}