Pagini recente » Cod sursa (job #14439) | Cod sursa (job #2816704) | Cod sursa (job #2294) | Cod sursa (job #1065954) | Cod sursa (job #3140946)
using namespace std;
#include<iostream>
#include<fstream>
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int k, y, x;
///1 4
///2 3
int ans(int k, int x, int y) {
//cout << k << " " << x << " " << y << endl;
if (k == 0) {
return 0;
}
k--;
int d = (1<<k);
if (x <= d && y <= d) { ///cadranul 1
int copiex = x;
x = y;
y = copiex;
return ans(k, x, y); ///intorc figura la 90 grade in sens invers trigonometric
}
if (x > d && y <= d) { /// cadranul 2
// cout << "adaug: " << d*d << endl;
return d*d + ans(k, x-d, y); /// nu intorc figura, dar o translatez cu d pozitii in sus
}
if (x > d && y > d) { ///cadranul 3
//cout << "adaug: " << 2*d*d << endl;
return 2*d*d + ans(k, x-d, y-d); /// nu intorc figura, dar o translatez cu d pozitii in sus si d pozitii in stanga
}
if (x <= d && y > d) { ///cadranul 4
y -= d;
//cout << x << " " << y << endl;
// int copiey = y;
// y = 2*d - x + 1;
// x = 2*d - copiey+1;
// cout << "adaug: " << 3*d*d << endl;
return 3*d*d + ans(k, x, y); ///intorc figura la 90 grade in sens trigonometric
}
}
int main() {
fin >> k >> y >> x;
fout << ans(k, x, y);
return 0;
}