Cod sursa(job #2151670)

Utilizator RobybrasovRobert Hangu Robybrasov Data 4 martie 2018 18:50:34
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int calculate(int n, int x, int y) {
    if (n == 1) {
        return 0;
    } else {
        int hn = n >> 1;
        int sf = hn * hn - 1;
        if (x <= hn) {
            if (y <= hn) {
                return calculate(hn, y, x);
            } else {
                y -= hn;
                return 3 * sf + 3 + calculate(hn, hn - y + 1, hn - x + 1);
            }
        } else {
            if (y <= hn) {
                x -= hn;
                return sf + 1 + calculate(hn, x, y);
            } else {
                x -= hn;
                y -= hn;
                return 2 * sf + 2 + calculate(hn, x, y);
            }
        }
    }
    return 0;
}

int main() {
    ifstream fin("fractal.in");
    ofstream fout("fractal.out");
    int k, x, y;
    fin >> k >> y >> x;
    fout << calculate(1 << k, x, y);

    return 0;
}