Cod sursa(job #1210324)

Utilizator Kerriganamihut Kerrigan Data 19 iulie 2014 17:00:41
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.47 kb
/******************************************************************************************
*           .--.																		  *
* ::\`--._,'.::.`._.--'/::			@author Ana M. Mihut	@course InfoArena Tryout	  *
* ::::. `  __::__ ' .:::::			@alias  LT-Kerrigan		@date   08.07.2014			  *
* ::::::-:.`'..`'.:-::::::			@link   http://infoarena.ro/problema/fractal		  *
* ::::::::\ `--' /::::::::			@detail potential for divide et impera				  *
*																						  *
*******************************************************************************************/
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;

unsigned short int k;
unsigned int x, y;

unsigned int DetSquareQuarter(unsigned int side, unsigned short int k, unsigned int x, unsigned int y){
	if (x == 1 && y == 1)
		return 0;
	if (x <= (1 << (k - 1)) && y <= (1 << (k - 1)))
		return DetSquareQuarter(side / 4, k - 1, y, x);
	if (y <= (1 << (k - 1)))
		return side / 4 + DetSquareQuarter(side / 4, k - 1, x - (1 << (k - 1)), y);
	if (x>(1 << (k - 1)) && y>(1 << (k - 1)))
		return side / 2 + DetSquareQuarter(side / 4, k - 1, x - (1 << (k - 1)), y - (1 << (k - 1)));
	y = y - (1 << (k - 1));
	return side / 4 * 3 + DetSquareQuarter(side / 4, k - 1, (1 << (k - 1)) - y + 1, (1 << (k - 1)) - x + 1);
}

int main() {

	freopen("fractal.in", "r", stdin);
	freopen("fractal.out", "w", stdout);
	scanf("%d %d %d", &k, &y, &x);
	printf("%d\n", DetSquareQuarter(1 << 2 * k, k, x, y));
}