Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #1219986)
//Basic libraries
#include <iostream>
#include <fstream>
#include <stdio.h>//cerut de evaluator (cred...)
using namespace std;
void rot ( int n, int *x, int *y, int rx, int ry )
{
if ( ry == 0 )
{
if ( rx == 1 )
{
*x = n - 1 - *x;
*y = n - 1 - *y;
}
int t = *x;
*x = *y;
*y = t;
}
}
int xy2d ( int n, int x, int y )
{
int rx, ry, s, d = 0;
for ( s = n / 2; s > 0; s /= 2 )
{
rx = ( x & s ) > 0;
ry = ( y & s ) > 0;
d += s * s * ( ( 3 * rx ) ^ ry );
rot ( s, &x, &y, rx, ry );
}
return d;
}
int main()
{
ifstream f ( "fractal.in" );
ofstream g ( "fractal.out" );
int k, x, y;
f >> k >> x >> y;
//flip x and y to appropriate coordinates
int W = 1;
for ( int i = 0; i < k; i++ ) W *= 2; //W = 2^k;
//normalize coordinates
x -= 1;
y -= 1;
g << xy2d ( W, x, y );
f.close();
g.close();
return 0;
}