Cod sursa(job #2277078)

Utilizator VadimCCurca Vadim VadimC Data 5 noiembrie 2018 19:36:20
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

ifstream fin("fractal.in");
ofstream fout("fractal.out");

int k, x, y;
int rez;

void f(int, int, int);

int main(){
	fin >> k >> y >> x;
	f(k, x, y);
	fout << 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);
		}
	}
}