Cod sursa(job #2224743)

Utilizator LIR16LazarIonutRadu LIR16 Data 24 iulie 2018 21:59:26
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

// 1 4
// 2 3
// cadranul 1 este rotit cu -90 grade, iar cadranul 4 e rotit cu 90 grade
//nou_x , nou_y = coordonatele punctului raportat la cadranul in care se afla.
//nou_capat1, nou_capat2 = capetele noului interval in care se poate afla punctul

ifstream in("fractal.in");
ofstream out("fractal.out");

int Pozitie( int ordin, int x, int y, int capat1, int capat2 )
{
    int nou_x, nou_y, nou_capat1, nou_capat2, cadran;
    if( x <= pow(2,ordin-1) && y <= pow(2,ordin-1) )
    {
        cadran = 1;
        nou_x = x;
        nou_y = y;
        // rotatie -90 grade
        int schimb;
        schimb = nou_x;
        nou_x = nou_y;
        nou_y = schimb;
        nou_capat1 = capat1;
        nou_capat2 = capat1 + pow(4,ordin)/4 - 1;
    }
    else if( x <= pow(2,ordin-1) && y > pow(2,ordin-1) )
    {
        cadran = 2;
        nou_x = x;
        nou_y = y - pow(2,ordin-1);
        nou_capat1 = capat1 + pow(4,ordin)/4;
        nou_capat2 = capat1 + pow(4,ordin)/2 - 1;
    }
    else if( x > pow(2,ordin-1) && y > pow(2,ordin-1) )
    {
        cadran = 3;
        nou_x =  x - pow(2,ordin-1);
        nou_y =  y - pow(2,ordin-1);
        nou_capat1 = capat1 + pow(4,ordin)/2;
        nou_capat2 = capat1 + 3*pow(4,ordin)/4 - 1;
    }
    else if( x > pow(2,ordin-1) && y <= pow(2,ordin-1) )
    {
        cadran = 4;
        nou_x = x - pow(2,ordin-1);
        nou_y = y;
        // rotatie 90 grade
        int retine = nou_x;
        nou_x = pow(2,ordin-1)+1-nou_y;
        nou_y = pow(2,ordin-1)+1-retine;
        nou_capat1 = capat1 + 3*pow(4,ordin)/4;
        nou_capat2 = capat1 + pow(4,ordin) - 1;
    }

    if( capat1 == capat2 || ordin<=-10)
        return capat1;
    return Pozitie(ordin-1, nou_x, nou_y, nou_capat1, nou_capat2);
}

int main()
{
    int ordin, x, y;
    in >> ordin >> x >> y;

    out << Pozitie(ordin, x, y, 1, pow(2,2*ordin)) - 1;
    return 0;
}