Pagini recente » Cod sursa (job #1203431) | Cod sursa (job #582374) | Cod sursa (job #1962030) | Cod sursa (job #1922571) | Cod sursa (job #2030928)
#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
int f(int k,short x,short y)
{
if(k==1)
{
if(x==1){
if(y==1) return 0;
if(y==2) return 1;
}
if(x==2)
{
if(y==1) return 3;
if(y==2) return 2;
}
}
else
{
if(x<=pow(2,k-1)&&y<=pow(2,k-1))
return f(k-1,y,x);
if(x<=pow(2,k-1)&&y>pow(2,k-1))
return pow(4,k-1)+f(k-1,x,y-pow(2,k-1));
if(x>pow(2,k-1)&&y>pow(2,k-1))
return 2*pow(4,k-1)+f(k-1,x-pow(2,k-1),y-pow(2,k-1));
if(x>pow(2,k-1)&&y<=pow(2,k-1))
return 3*pow(4, k-1)+ f(k-1, pow(2, k-1)-y+1, pow(2,k-1)-(x-pow(2, k-1))+1);
}
}
int main()
{ ifstream in("fractal.in");
ofstream out("fractal.out");
int k,x,y;
in>>k>>x>>y;
out<<f(k,x,y);
return 0;
}