Pagini recente » Cod sursa (job #1001806) | Cod sursa (job #2504889)
#include <fstream>
using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
void work(int k, int x, int y, int nrP){
if(k == 1){
if(x == 1 && y == 1)
fout << nrP << '\n';
if(x == 2 && y == 1)
fout << nrP + 1 << '\n';
if(x == 2 && y == 2)
fout << nrP + 2 << '\n';
if(x == 1 && y == 2)
fout << nrP + 3 << '\n';
}
else {
int lim = (1 << (k - 1));
int add = lim * lim;
if(x <= lim && y <= lim)
work(k - 1, y, x, nrP);
else if(x > lim && y <= lim)
work(k - 1, x - lim, y, nrP + add);
else if(x > lim && y > lim)
work(k - 1, x - lim, y - lim, nrP + 2 * add);
else
work(k - 1, lim - (y - lim) + 1, lim - x + 1, nrP + 3 * add);
}
}
int main()
{
int k, x, y;
fin >> k >> y >> x;
work(k, x, y, 0);
return 0;
}