Cod sursa(job #1291565)

Utilizator pitradaPit-Rada Ionel-Vasile pitrada Data 12 decembrie 2014 22:45:37
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<fstream>
using namespace std;

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

int K, lin, col, w, d, aux;

int main()
{
    fin>>K>>col>>lin;
    w=0;
    while(K>0)
    {
        K--;
        d=(1<<K);
        if(lin<=d)
        {
            if(col>d)
            {
                col=2*d+1-col;
                w=w+d*d*3;
            }
            aux=col;
            col=d+1-aux;
            lin=aux;
        }
        else
        {
            if(col>d)
            {
                col=2*d+1-col;
                w=w+d*d;
            }
            lin=lin-d;
            w=w+d*d;
        }
    }
    fout<<w;
    fout.close();
    return 0;
}