Pagini recente » Cod sursa (job #1865748) | Cod sursa (job #1333702) | Cod sursa (job #2105235) | Cod sursa (job #412817) | Cod sursa (job #841374)
Cod sursa(job #841374)
#include <fstream>
using namespace std;
ifstream in("fractal.in");
ofstream out("fractal.out");
int f(int k,int x,int y)
{
int cmp,cadran;
if(!k) return 0;
cmp=1<<k-1;
if(x<=cmp)
if(y<=cmp) cadran=1;
else cadran=2;
else
if(y>cmp) cadran=3;
else cadran=4;
switch(cadran)
{case 1: return f(k-1,y,x); break;
case 2: return cmp*cmp + f(k-1,x,y-cmp); break;
case 3: return 2*cmp*cmp + f(k-1,x-cmp,y-cmp); break;
case 4: return 3*cmp*cmp + f(k-1,cmp-y+1,2*cmp-x+1); break;}
}
int main()
{
int k,x,y;
in>>k>>x>>y;
out<<f(k,x,y);
return 0;
}