Pagini recente » Cod sursa (job #1899350) | Cod sursa (job #13319) | Cod sursa (job #2788754) | Cod sursa (job #2829496) | Cod sursa (job #2224741)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
// 1 4
// 2 3
//noul_x , noul_y = coordonatele punctului raportat la cadranul in care se afla.
ifstream in("fractal.in");
ofstream out("fractal.out");
int Pozitie( int ordin, int x, int y, int capat1, int capat2 )
{
int nou_x, nou_y, nou_capat1, nou_capat2, cadran;
if( x <= pow(2,ordin-1) && y <= pow(2,ordin-1) )
{
cadran = 1;
nou_x = x;
nou_y = y;
int schimb;
schimb = nou_x;
nou_x = nou_y;
nou_y = schimb;
nou_capat1 = capat1;
nou_capat2 = capat1 + pow(4,ordin)/4 - 1;
}
else if( x <= pow(2,ordin-1) && y > pow(2,ordin-1) )
{
cadran = 2;
nou_x = x;
nou_y = y - pow(2,ordin-1);
nou_capat1 = capat1 + pow(4,ordin)/4;
nou_capat2 = capat1 + pow(4,ordin)/2 - 1;
}
else if( x > pow(2,ordin-1) && y > pow(2,ordin-1) )
{
cadran = 3;
nou_x = x - pow(2,ordin-1);
nou_y = y - pow(2,ordin-1);
nou_capat1 = capat1 + pow(4,ordin)/2;
nou_capat2 = capat1 + 3*pow(4,ordin)/4 - 1;
}
else if( x > pow(2,ordin-1) && y <= pow(2,ordin-1) )
{
cadran = 4;
nou_x = x - pow(2,ordin-1);
nou_y = y;
int retine = nou_x;
nou_x = pow(2,ordin-1)+1-nou_y;
nou_y = pow(2,ordin-1)+1-retine;
nou_capat1 = capat1 + 3*pow(4,ordin)/4;
nou_capat2 = capat1 + pow(4,ordin) - 1;
}
if( capat1 == capat2 || ordin<=-10)
return capat1;
return Pozitie(ordin-1, nou_x, nou_y, nou_capat1, nou_capat2);
}
int main()
{
int ordin, x, y;
in >> ordin >> x >> y;
out << Pozitie(ordin, x, y, 1, pow(2,2*ordin)) - 1;
return 0;
}