Cod sursa(job #1469656)

Utilizator FairPlay94George Cioroiu FairPlay94 Data 9 august 2015 02:09:43
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <climits>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <map>
#include <algorithm>
#include <string>

#define nmax 1700000

using namespace std;

int f(int p, int x, int y) {
    if (p == 0)
        return 0;
    bool stanga = x <= p;
    bool jos = y <= p;
    int c;
    if (jos)
        if (stanga)
            return f(p / 2, y, x);
        else
            return 3 * p * p + f(p / 2, p - y + 1, 2 * p - x + 1);
    else if (stanga)
        return p * p + f(p / 2, x, y - p);
    else
        return 2 * p * p + f(p / 2, x - p, y - p);
}

int main() {
    freopen("fractal.in", "r", stdin);
    freopen("fractal.out", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int k, x, y, p = 1;
    cin >> k >> x >> y;
    for (int i = 1; i < k; i++)
        p *= 2;
    int ans = f(p, x, y);
    cout << ans;

    return 0;
}