Cod sursa(job #2488638)

Utilizator richard26Francu Richard richard26 Data 7 noiembrie 2019 12:03:18
Problema Fractal Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.4 kb
	
#include <bits/stdc++.h>
	
 
	
using namespace std;
	
 
	
long long pw2[100];
	
 
	
int divide(int x, int y, int dim) {
	
 
	
    if (dim == 1) {
	
        if (x == 1 && y == 1) {
	
            return 0;
	
        } 
	
 
	
        if (x == 1 && y == 2) {
	
            return 3;
	
        }
	
 
	
        if (x == 2 && y == 1) {
	
            return 1;
	
        }
	
 
	
        if (x == 2 && y == 2) {
	
            return 2;
	
        }
	
    } else {
	
 
	
        if (x <= pw2[dim - 1] && y <= pw2[dim - 1] ) {
	
 
	
            return divide(y, x, dim - 1);
	
        } 
	
        
	
        else if (x <= pw2[dim - 1] && y > pw2[dim - 1]) {
	
            return 3 * pw2[dim] + divide(pw2[dim - 1] - y  + pw2[dim - 1] + 1, pw2[dim - 1] - x + 1, dim - 1);
	
        }
	
 
	
        else if (x > pw2[dim - 1] && y <= pw2[dim - 1]) {
	
 
	
            return pw2[dim] + divide(x - pw2[dim - 1], y, dim - 1);
	
        }
	
 
	
        else if (x > pw2[dim - 1] && y > pw2[dim - 1]) {
	
 
	
            return 2 * pw2[dim] + divide(x - pw2[dim - 1], y - pw2[dim - 1], dim - 1);
	
        }
	
    }
	
 
	
    
	
    
	
}
	
 
	
int main()
	
{
	
 
	
    ifstream f("fractal.in");
	
    ofstream g("fractal.out");
	
    pw2[0] = 1;
	
    int x, y, k;
	
 
	
    
	
    cin >> k >> x >> y;
	
    for (int i = 1; i <= k; i++) {
	
        pw2[i] = 2 * pw2[i - 1];
	
        //cout << pw2[i] << endl;
	
    }
	
    cout << divide(y, x, k);
	
}