Cod sursa(job #1242586)
Utilizator | Bacotiu Gabi gbib | Data | 14 octombrie 2014 18:38:54 |
---|---|---|---|
Problema | Fractal | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <fstream>
using namespace std;
ifstream in("fractal.in");
ofstream out("fractal.out");
int sol=0;
void rez(int k, int x, int y)
{
if(k==0)
return;
int put;
put=(1<<(k-1));
if(x<=put&&y<=put)
{
rez(k-1,y,x);
}
else
if(x>put&&y<=put)
{
sol+=put*put;
rez(k-1,x-put,y);
}
else
if(x>put&&y>put)
{
sol+=2*put*put;
rez(k-1,x-put,y-put);
}
else
if(x<=put&&y>put)
{
sol+=3*put*put;
rez(k-1,put-(y-put)+1,put-x+1);
}
}
int main()
{
int x,y,k;
in>>k>>x>>y;
rez(k,y,x);
out<<sol<<'\n';
return 0;
}