Cod sursa(job #1022569)

Utilizator ELHoriaHoria Cretescu ELHoria Data 5 noiembrie 2013 18:48:23
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <cstring>
#include <algorithm>

using namespace std;

ifstream cin("fractal.in");
ofstream cout("fractal.out");

int main()
{
	int K, x, y;
	while(cin>>K>>x>>y) {
		int ret = 0;
		swap(x,y);
		for(int k = K;k >= 1;k--) {
			int squareSize = 1<<(2*k - 2);
			if(x <= (1<<(k - 1)) && y <= (1<<(k - 1))) {
				swap(x,y);
			} else
			if(x > (1<<(k - 1)) && y <= (1<<(k - 1))) {
				ret += squareSize;
				x -= 1<<(k - 1);
			} else
			if(x > (1<<(k - 1)) && y > (1<<(k - 1))) {
				x -= 1<<(k - 1);
				y -= 1<<(k - 1);
				ret += 2*squareSize;
			} else {
				ret += 3*squareSize;
				int aux = x;
				x = (1<<k) - y + 1;
				y = (1<<(k - 1)) - aux + 1;
			}
		}
		cout<<ret<<"\n";
	}
	return 0;
}