Cod sursa(job #1672706)

Utilizator stoianmihailStoian Mihail stoianmihail Data 3 aprilie 2016 00:08:42
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#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;
}