Cod sursa(job #1852338)

Utilizator maria15Maria Dinca maria15 Data 20 ianuarie 2017 18:42:02
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#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;
}