Cod sursa(job #1103584)

Utilizator s1mpMihai Alexandru s1mp Data 9 februarie 2014 20:25:48
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<iostream>
#include<fstream>

using namespace std;

int fractal(int K, long long X, long long Y) {
	if (K == 1) {
		return 0;
	} else {
		K/=2;
		if (X<=K) {
			if (Y<=K) {
				return fractal(K,Y,X);
			} else {
				return fractal(K,X,Y-K) + K*K;
			}
		} else {
			if (Y<=K) {
				return fractal(K,K-Y+1,2*K-X+1) + K*K*3;
			} else {
				return fractal(K,X-K,Y-K) + K*K*2;
			}
		}
	}
}

int main() {
	ifstream f("fractal.in");
	ofstream g("fractal.out");
	int K;
	long long X,Y;
	f>>K;
	f>>X;
	f>>Y;
	cout<<fractal(1<<K,X,Y);
	f.close();
	g.close();
	return 0;
}