Pagini recente » Cod sursa (job #2058241) | Cod sursa (job #1860358) | Cod sursa (job #81944) | Cod sursa (job #1938159) | Cod sursa (job #1940487)
#include <fstream>
using namespace std;
ifstream fin ("fractal.in");
ofstream fout("fractal.out");
int x, y, nextL, nextx, nexty, ordin, L, nr;
int main ()
{
fin >> ordin >> y >> x;
// cate puncte sunt pana in locul i,j din matricea ordin (4^ordin elemente)
L = (1<<ordin);
while (L != 1)
{
nextL = L/2;
if (x <= nextL)
{
if (y <= nextL)
{
// stanga sus
nextx = y;
nexty = nextL-x+1;
x = nextx;
y = nexty;
y = nextL-y+1;
}
else
{
// dreapta sus
nr += 3*nextL*nextL;
y -= nextL;
nextx = nextL-y+1;
nexty = x;
x = nextx;
y = nexty;
y = nextL-y+1;
}
}
else
{
if (y <= nextL)
{
// stanga jos
nr += nextL*nextL;
x -= nextL;
}
else
{
// dreapta jos
nr += 2*nextL*nextL;
x -= nextL;
y -= nextL;
}
}
L /= 2;
}
fout << nr;
return 0;
}