Pagini recente » Cod sursa (job #2901060) | Cod sursa (job #1938007) | Cod sursa (job #2883237) | Cod sursa (job #2894730) | Cod sursa (job #1819926)
#include <fstream>
#include <iostream>
#include <cmath>
using namespace std;
int k, x, y;
int c[2][2] = { {1, 4}, {2, 3} }; // |1 4|
int MatLen[16]; // |2 3|
int fstLen[2][2] = { {0, 3}, {1, 2} };
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int FindLength(int k, int x, int y)
{
if (k == 1)
return fstLen[x - 1][y - 1];
int dim = pow(k, 2);
int cadr = c[x > dim / 2][y > dim / 2];
switch (cadr)
{
case 1: return 0 * MatLen[k - 1] + 0 + FindLength(k - 1, y, x);
case 2: return 1 * MatLen[k - 1] + 1 + FindLength(k - 1, x - dim / 2, y);
case 3: return 2 * MatLen[k - 1] + 2 + FindLength(k - 1, x - dim / 2, y - dim / 2);
case 4: return 3 * MatLen[k - 1] + 3 + FindLength(k - 1, dim - y + 1, dim / 2 - x + 1);
}
}
int main()
{
fin >> k >> y >> x;
for (int i = 1; i < k; i++)
MatLen[i] = 4 * MatLen[i - 1] + 3;
fout << FindLength(k, x, y);
return 0;
}