Pagini recente » Cod sursa (job #2555762) | Cod sursa (job #589003) | Cod sursa (job #2462572) | Cod sursa (job #923609) | Cod sursa (job #1672706)
#include <iostream>
#include <fstream>
using namespace std;
int solutie (int x, int y, int ordin) {
if (ordin == 1) {
if (x == 1 && y == 1) {
return 0;
}
if (x == 2 && y == 1) {
return 1;
}
if (x == 2 && y == 2) {
return 2;
}
return 3;
}
int putere = 1 << (ordin - 1);
if (x <= putere && y <= putere) { // zona I
return solutie (y, x, ordin - 1);
}
if (x > putere && y <= putere) { // zona II
return (1 << 2 * (ordin - 1)) + solutie (x - putere, y, ordin - 1);
}
if (x > putere && y > putere) { // zona III
return (1 << (2 * ordin - 1)) + solutie (x - putere, y - putere, ordin - 1);
}
return (3 * (1 << 2 * (ordin - 1))) + solutie ((2 * putere) - y + 1, putere - x + 1, ordin - 1);
}
int main() {
ifstream file_in ("fractal.in");
ofstream file_out ("fractal.out");
int x, y, ordin, sol;
// Citirea datelor
file_in >> ordin >> x >> y;
// Calcularea solutiei
sol = solutie(y, x, ordin);
// Afisrea solutiei
file_out << sol;
return 0;
}