Cod sursa(job #829035)

Utilizator Detrol2kGuianu Leon Detrol2k Data 4 decembrie 2012 20:09:02
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;

long long compute(long long l, long long x, long long y)
{
	if(l == 1)
		return 0;
		
	l = l/2;
	
	if(x<=l && y<=l)//Cadranul 1
		return compute(l,y,x);
	if(x<=l && y>l)//Cadranul 2
		return l*l+compute(l,x,y-l);
	if(x>l && y>l)//Cadranul 3
		return 2*l*l+compute(l,x-l,y-l);
	if(x>l && y<=l)//Cadranul 4
		return 3*l*l+compute(l,l-y+1,2*l-x+1);
}

int main()
{
	ifstream f("fractal.in");
	ofstream g("fractal.out");
	
	long long k, x, y, rez;
	
	//Read
	f>>k>>x>>y;
	
	//Compute
	rez = compute(1<<k,x,y);
	
	//Print
	g<<rez;
}