Cod sursa(job #2320281)

Utilizator vladadAndries Vlad Andrei vladad Data 14 ianuarie 2019 16:42:46
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream fi("fractal.in");
ofstream g("fractal.out");

int k, x, y;
int rez;

void f(int, int, int);

int main(){
	fi >> k >> y >> x;
	f(k, x, y);
	g << rez;
}

void f(int k, int x, int y){
	int n;
	if(k > 0){
		k--;
		n = pow(2, k);
		if(x <= n && y <= n){
			f(k, y, x);
		}
		else if(x > n && y <= n){
			rez += n * n;
			f(k, x - n, y);
		}
		else if(x > n && y > n){
			rez += 2 * n * n;
			f(k, x - n, y - n);
		}
		else if(x <= n && y > n){
			rez += 3 * n * n;
			f(k, 2*n + 1 - y, n - x + 1);
		}
	}
}