Cod sursa(job #1593555)

Utilizator ArceyGeorge Cioroiu Arcey Data 8 februarie 2016 18:14:51
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <cstdio>
#include <iostream>
#include <set>
#include <climits>
#include <map>
#include <algorithm>
#include <list>
#include <vector>
#include <utility>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <string>

using namespace std;

int f(int k, int x, int y) {
    if (k == 0) {
        return 0;
    }

    bool right = (x > (1 << (k - 1)));
    bool down = (y > (1 << (k - 1)));

    int square;
    if (right)
        if (down)
            square = 2;
        else
            square = 3;
    else if (down)
        square = 1;
    else
        square = 0;

    int xNew, yNew;
    switch(square) {
    case 0:
        xNew = (1 << (k - 1)) - y + 1;
        yNew = (1 << (k - 1)) - x + 1;
        break;
    case 1:
        xNew = x;
        yNew = y - (1 << (k - 1));
        break;
    case 2:
        xNew = x - (1 << (k - 1));
        yNew = y - (1 << (k - 1));
        break;
    case 3:
        xNew = (1 << (k - 1)) - y + 1;
        yNew = (1 << k) - x + 1;
    }

    return square * k * k + f(k - 1, xNew, yNew);
}

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

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

    int k, x, y;
    cin >> k >> x >> y;
    int ans = f(k, x, y);
    cout << ans;

    return 0;
}