Cod sursa(job #1598880)

Utilizator Data 13 februarie 2016 13:58:29 Fractal 100 cpp done Arhiva de probleme 1.65 kb
``````#include <iostream>
#include <fstream>
#include <string.h>
//#include <vector>
//#include <queue>
//#include <algorithm>

using namespace std;

struct zonee {
int x,y;
};
zonee z[4];

int x, y,res = 0;

void getZona(int& xx, int& yy, int kk){
int div = 1 << (kk - 1);
//if (kk == 1) div = 0;
bool q = false;
int _x = (xx >= div) ? 1 : 0;
int _y = (yy >= div) ? 1 : 0;

int i = 0;
while (i < 3 && !q) {
if (z[i].x == _x && z[i].y == _y)
q = true;
else i++;
}

switch (i)
{
case 0:
swap(z[1], z[3]);
break;
case 1:
res += 1 << ( 2 * (kk - 1));		// 2^2^k-1
break;
case 2:
res += 1 << (1 + 2 * (kk - 1) );		// 2^2^k-1
break;
case 3 :
res += 3 * 1 << ( 2 * (kk - 1));		// 2^2^k-1
swap(z[0], z[2]);
break;
}

if (xx >= div ) xx -= div;
if (yy >= div ) yy -= div;
}

int main(){
freopen("fractal.in", "r", stdin);
freopen("fractal.out", "w", stdout);
int k, n, m;
scanf("%d %d %d", &k, &x, &y);
x--; y--;
int u = x, v = y;

z[0].x = 0; z[0].y = 0;
z[1].x = 0; z[1].y = 1;
z[2].x = 1; z[2].y = 1;
z[3].x = 1; z[3].y = 0;

for (int i = k; i; i--)
getZona(u, v, i);

printf("%d ", res);
fclose(stdin);
fclose(stdout);
return 0;
}

/*
int rek(int k){
if (k == 0) {
cout << "Coord : " << u << "  " << v << endl;
if (x == u && v == y){
q = true;
return 0;
}
else return 1;
}
int s = rek(k - 1);
if (q) return s;

v = v + ((k + 1) % 2);
u = u + (k % 2);
s += rek(k-1);
if (q) return s;

v = v + (k % 2);
u = u + ((k + 1) % 2);
s += rek(k-1);
if (q) return s;

v = v - ((k + 1) % 2);
u = u - (k % 2);
s += rek(k-1);
return s;
}
*/``````