Pagini recente » Cod sursa (job #2348580) | Cod sursa (job #1108774) | Cod sursa (job #2810504) | Cod sursa (job #1107509) | Cod sursa (job #1852338)
#include <fstream>
using namespace std;
int x, y, nextL, nextx, nexty, ordin, L, nr;
ifstream fin ("fractal.in");
ofstream fout("fractal.out");
int main () {
fin>>ordin>>y>>x;
// cate puncte sunt pana in locul i,j din matricea ordin (4^ordin elemente)
//1 4 4^1
//2 16 4^2
//3 64 4^3
L=(1<<ordin);
while (L!=1) {
nextL = L/2;
if (x <= nextL) {
if (y <= nextL) {
// stanga sus
nextx = y;
nexty = nextL - x + 1;
x = nextx;
y = nexty;
y = nextL - y + 1;
} else {
// dreapta sus
nr += 3 * nextL * nextL;
y -= nextL;
nextx = nextL - y + 1;;
nexty = x;
x = nextx;
y = nexty;
y = nextL - y + 1;
}
} else {
if (y <= nextL) {
// stanga jos
nr += nextL*nextL;
x -= nextL;
} else {
// dreapta jos
nr += 2*nextL*nextL;
x -= nextL;
y -= nextL;
}
}
L /= 2;
}
fout<<nr;
return 0;
}