Pagini recente » Cod sursa (job #2558291) | Cod sursa (job #2780430) | Cod sursa (job #2461804) | Cod sursa (job #2405292) | Cod sursa (job #1228007)
#include <fstream>
const char IN [ ] = "fractal.in" ;
const char OUT [ ] = "fractal.out" ;
using namespace std;
ifstream fin ( IN ) ;
ofstream fout ( OUT ) ;
inline int arie ( int x )
{
return x * x ;
}
int fractal ( int x , int y , int ordin )
{
if ( ordin < 0 )
return 0 ;
int lung = 1 << ordin ;
if ( x <= lung and y <= lung )
return fractal ( y , x , ordin - 1 ) ;
else if ( x > lung and y <= lung )
return arie ( lung ) + fractal ( x - lung , y , ordin - 1 ) ;
else if ( x > lung and y > lung )
return 2 * arie ( lung ) + fractal ( x - lung , y - lung , ordin - 1 ) ;
else
return 3 * arie ( lung ) + fractal ( ( lung << 1 ) - y + 1 , lung - x + 1 , ordin - 1 ) ;
}
int main()
{
int ordin, x , y ;
fin >> ordin >> x >> y ;
fout << fractal ( x , y , ordin ) ;
return 0;
}