Pagini recente » Cod sursa (job #1365636) | Cod sursa (job #162925) | Cod sursa (job #1686554) | Cod sursa (job #2382821) | Cod sursa (job #2490633)
#include <fstream>
#include <iostream>
using namespace std;
int p[18];
int fractal(int k, int x, int y)
{
if(k == 0) return 0;
if(x <= p[k - 1] && y <= p[k - 1])
return fractal(k - 1, y, x);
if(x <= p[k - 1] && y > p[k - 1])
return fractal(k - 1, x, y - p[k - 1]) + p[k - 1] * p[k - 1];
if(x > p[k - 1] && y > p[k - 1])
return fractal(k - 1,x - p[k - 1],y - p[k - 1]) + p[k - 1] * p[k - 1] * 2;
return fractal(k - 1,p[k - 1] - y + 1,p[k] - x + 1) + 3 * p[k - 1] * p[k - 1];
}
int main()
{
ifstream f("fractal.in");
ofstream g("fractal.out");
int k,x,y;
f >> k >> x >> y;
if ( k == 1 ){
g << 0;
f.close();
g.close();
return 0;
}
p[0] = 1;
for(int i = 1;i <= k; i++)
p[i] = p[i - 1] * 2;
int result = fractal(k, x, y);
g << result;
f.close();
g.close();
return 0;
}