Pagini recente » Monitorul de evaluare | Cod sursa (job #2097913) | Cod sursa (job #692449) | Cod sursa (job #2401762) | Cod sursa (job #2488982)
#include<iostream>
#include<fstream>
#include<cstdio>
using namespace std;
ifstream f("fractal.in");
ofstream g("fractal.out");
int raspuns = 0;
void recursiv(int k, int x, int y)
{
if (k != 0)
{
int mij = 1;
for (int i = 1; i < k; i++)
mij = mij * 2;
if (mij < x && mij < y)
{
raspuns = raspuns + 2 * mij * mij;
recursiv(k - 1, x - mij, y - mij);
}
if (mij >= x && mij >= y)
{
recursiv(k - 1, y, x);
}
if (mij < x && mij >= y)
{
raspuns = raspuns + mij * mij;
recursiv(k - 1, x - mij, y);
}
if (mij >= x && mij < y)
{
raspuns = raspuns + 3 * mij * mij;
recursiv(k - 1, mij * 2 - y + 1, mij - x + 1);
}
}
return;
}
int main()
{
int k, x, y;
f >> k >> y >> x;
recursiv(k, x, y);
g << raspuns;
return 0;
}