Cod sursa(job #2872368)

Utilizator MortemPlaiasu Iulia-Silvia Mortem Data 16 martie 2022 21:21:44
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>

using namespace std;

FILE *fin = fopen("fractal.in", "r");
FILE *fout = fopen("fractal.out", "w");

int main()
{
    int k, x, y;
    fscanf(fin, "%d %d %d", &k, &x, &y);
    swap(x, y);
    long long countt = 0;
    while (k >= 0)
    {
        if (x <= (1 << k) && y <= (1 << k))
        {
            int aux = x;
            x = y;
            y = aux;
        }
        else if (x <= (1 << k) && y > (1 << k))
        {
            countt += (1 << k) * (1 << k);
            y = y - (1 << k);
        }
        else if (y > (1 << k))
        {
            countt += (1 << k) * (1 << k) * 2;
            y = y - (1 << k);
            x = x - (1 << k);
        }
        else
        {
            countt += (1 << k) * (1 << k) * 3;
            int aux = x;
            x = (1 << k) - y + 1;
            y = (1 << (k + 1)) - aux + 1;
        }
        printf("%d %d %d\n", k, x, y);
        k--;
    }
    fprintf(fout, "%lld\n", countt);
}