Cod sursa(job #1293208)

Utilizator adnionutCojocaru Ionut adnionut Data 15 decembrie 2014 16:22:36
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 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=col-d;
                //rot stg + sim vert
                aux=lin;
                lin=d+1-col;
                col=aux;
                col=d+1-col;
                w=w+d*d*3;
            }
            else
            {
                //rot dr + sim vert
                aux=lin;
                lin=col;
                col=d+1-aux;
                col=d+1-col;
            }
        }
        else
        {
            if(col>d)
            {
                w=w+d*d*2;
                lin=lin-d;
                col=col-d;
            }
            else
            {
                w=w+d*d;
                lin=lin-d;
            }
        }
    }
    fout<<w;
    fout.close();
    return 0;
}