Cod sursa(job #2833806)

Utilizator Stefan_DomuncoStefan Domunco Stefan_Domunco Data 15 ianuarie 2022 18:50:27
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 8.2 kb
#include <bits/stdc++.h>

using namespace std;

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

int k, x, y;
//int linStart, linStop, colStart, colStop;

int DEI(int k, int linStart, int colStart, int linStop, int colStop, int orderType)
{
    if(k == 0)
        return 0;

    int linmij, colmij, sol = 0, nrElCadran, counted = 0;
    linmij = (linStart + linStop) / 2;
    colmij = (colStart + colStop) / 2;

    nrElCadran = 1ll * (linStop - linStart + 1) * (colStop - colStart + 1) / 4;

    ///1 4   1 2
    ///2 3   3 4
    if(orderType == 1)
    {
        //cadran 1 ... st sus
        if(linStart <= x && x <= linmij && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linStart, colStart, linmij, colmij, 3);
        else counted += nrElCadran;

        //cadran 3 ... st jos
        if(linmij < x && x <= linStop && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linmij + 1, colStart, linStop, colmij, 1);
        else counted += nrElCadran;

        //cadran 4 ... dr jos
        if(linmij < x && x <= linStop && colmij < y && y <= colStop)
            return counted + DEI(k-1, linmij + 1, colmij + 1, linStop, colStop, 1);
        else counted += nrElCadran;

        //cadran 2 ... dr sus
        if(linStart <= x && x <= linmij && colmij < y && y <= colStop)
            return counted + DEI(k-1, linStart, colmij + 1, linmij, colStop, 8);
        else counted += nrElCadran;
    }

    ///4 1
    ///3 2
    else if(orderType == 2)
    {
        //cadran 2 ... dr sus
        if(linStart <= x && x <= linmij && colmij < y && y <= colStop)
            return counted + DEI(k-1, linStart, colmij + 1, linmij, colStop, 7);
        else counted += nrElCadran;

        //cadran 4 ... dr jos
        if(linmij < x && x <= linStop && colmij < y && y <= colStop)
            return counted + DEI(k-1, linmij + 1, colmij + 1, linStop, colStop, 2);
        else counted += nrElCadran;

        //cadran 3 ... st jos
        if(linmij < x && x <= linStop && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linmij + 1, colStart, linStop, colmij, 2);
        else counted += nrElCadran;

        //cadran 1 ... st sus
        if(linStart <= x && x <= linmij && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linStart, colStart, linmij, colmij, 4);
        else counted += nrElCadran;
    }

    ///1 2
    ///4 3
    else if(orderType == 3)
    {
        //cadran 1 ... st sus
        if(linStart <= x && x <= linmij && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linStart, colStart, linmij, colmij, 1);
        else counted += nrElCadran;

        //cadran 2 ... dr sus
        if(linStart <= x && x <= linmij && colmij < y && y <= colStop)
            return counted + DEI(k-1, linStart, colmij + 1, linmij, colStop, 3);
        else counted += nrElCadran;

        //cadran 4 ... dr jos
        if(linmij < x && x <= linStop && colmij < y && y <= colStop)
            return counted + DEI(k-1, linmij + 1, colmij + 1, linStop, colStop, 3);
        else counted += nrElCadran;

        //cadran 3 ... st jos
        if(linmij < x && x <= linStop && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linmij + 1, colStart, linStop, colmij, 6);
        else counted += nrElCadran;
    }

    ///4 3
    ///1 2
    else if(orderType == 4)
    {
        //cadran 3 ... st jos
        if(linmij < x && x <= linStop && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linmij + 1, colStart, linStop, colmij, 5);
        else counted += nrElCadran;

        //cadran 4 ... dr jos
        if(linmij < x && x <= linStop && colmij < y && y <= colStop)
            return counted + DEI(k-1, linmij + 1, colmij + 1, linStop, colStop, 4);
        else counted += nrElCadran;

        //cadran 2 ... dr sus
        if(linStart <= x && x <= linmij && colmij < y && y <= colStop)
            return counted + DEI(k-1, linStart, colmij + 1, linmij, colStop, 4);
        else counted += nrElCadran;

        //cadran 1 ... st sus
        if(linStart <= x && x <= linmij && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linStart, colStart, linmij, colmij, 2);
        else counted += nrElCadran;
    }

    ///2 3
    ///1 4
    else if(orderType == 5)
    {
        //cadran 3 ... st jos
        if(linmij < x && x <= linStop && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linmij + 1, colStart, linStop, colmij, 4);
        else counted += nrElCadran;

        //cadran 1 ... st sus
        if(linStart <= x && x <= linmij && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linStart, colStart, linmij, colmij, 5);
        else counted += nrElCadran;

        //cadran 2 ... dr sus
        if(linStart <= x && x <= linmij && colmij < y && y <= colStop)
            return counted + DEI(k-1, linStart, colmij + 1, linmij, colStop, 5);
        else counted += nrElCadran;

        //cadran 4 ... dr jos
        if(linmij < x && x <= linStop && colmij < y && y <= colStop)
            return counted + DEI(k-1, linmij + 1, colmij + 1, linStop, colStop, 7);
        else counted += nrElCadran;
    }

    ///3 2
    ///4 1
    else if(orderType == 6)
    {
        //cadran 4 ... dr jos
        if(linmij < x && x <= linStop && colmij < y && y <= colStop)
            return counted + DEI(k-1, linmij + 1, colmij + 1, linStop, colStop, 8);
        else counted += nrElCadran;

        //cadran 2 ... dr sus
        if(linStart <= x && x <= linmij && colmij < y && y <= colStop)
            return counted + DEI(k-1, linStart, colmij + 1, linmij, colStop, 6);
        else counted += nrElCadran;

        //cadran 1 ... st sus
        if(linStart <= x && x <= linmij && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linStart, colStart, linmij, colmij, 6);
        else counted += nrElCadran;

        //cadran 3 ... st jos
        if(linmij < x && x <= linStop && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linmij + 1, colStart, linStop, colmij, 3);
        else counted += nrElCadran;

    }

    ///2 1
    ///3 4
    else if(orderType == 7)
    {
        //cadran 2 ... dr sus
        if(linStart <= x && x <= linmij && colmij < y && y <= colStop)
            return counted + DEI(k-1, linStart, colmij + 1, linmij, colStop, 2);
        else counted += nrElCadran;

        //cadran 1 ... st sus
        if(linStart <= x && x <= linmij && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linStart, colStart, linmij, colmij, 7);
        else counted += nrElCadran;

        //cadran 3 ... st jos
        if(linmij < x && x <= linStop && colStart <= y && y <= colmij)
            return DEI(k-1, linmij + 1, colStart, linStop, colmij, 7);
        else counted += nrElCadran;

        //cadran 4 ... dr jos
        if(linmij < x && x <= linStop && colmij < y && y <= colStop)
            return counted + DEI(k-1, linmij + 1, colmij + 1, linStop, colStop, 5);
        else counted += nrElCadran;
    }

    ///3 4
    ///2 1
    else if(orderType == 8)
    {
        //cadran 4 ... dr jos
        if(linmij < x && x <= linStop && colmij < y && y <= colStop)
            return counted + DEI(k-1, linmij + 1, colmij + 1, linStop, colStop, 6);
        else counted += nrElCadran;

        //cadran 3 ... st jos
        if(linmij < x && x <= linStop && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linmij + 1, colStart, linStop, colmij, 8);
        else counted += nrElCadran;

        //cadran 1 ... st sus
        if(linStart <= x && x <= linmij && colStart <= y && y <= colmij)
            return counted + DEI(k-1, linStart, colStart, linmij, colmij, 8);
        else counted += nrElCadran;

        //cadran 2 ... dr sus
        if(linStart <= x && x <= linmij && colmij < y && y <= colStop)
            return counted + DEI(k-1, linStart, colmij + 1, linmij, colStop, 1);
        else counted += nrElCadran;
    }
}

int main()
{
    ///cadrane
    ///1 2
    ///3 4
    ///

    fin >> k >> x >> y;
    fout << DEI(k+1, 1, 1, 1 << (k+1), 1 << (k+1), 1);

    return 0;
}