Pagini recente » Cod sursa (job #732381) | Cod sursa (job #3187783) | Cod sursa (job #2526700) | Cod sursa (job #2241047) | Cod sursa (job #2253231)
#include<fstream>
using namespace std;
ifstream in("fractal.in");
ofstream out("fractal.out");
int p[17], k, x, y, pasi, a, b, i;
void fractal(int k, int x, int y) {
if (k > 0) {
if (x <= p[k - 1] && y <= p[k - 1]) {
fractal(k - 1, y, x);
}
if (x > p[k - 1] && y <= p[k - 1]) {
pasi += p[k - 1] * p[k - 1];
fractal(k - 1, x - p[k - 1], y);
}
if (x <= p[k - 1] && y > p[k - 1]) {
pasi += p[k - 1] * p[k - 1] * 3;
fractal(k - 1, p[k] + 1 - y, p[k - 1] - x + 1);
}
if (x > p[k - 1] && y > p[k - 1]) {
pasi += p[k - 1] * p[k - 1] * 2;
fractal(k - 1, x - p[k - 1], y - p[k - 1]);
}
}
return;
}
int main() {
in >> k >> y >> x;
p[0] = 1;
for (i = 1; i <= 15; i++) {
p[i] = p[i - 1] * 2;
}
fractal(k, x, y);
out << pasi;
return 0;
}