Cod sursa(job #1876271)

Utilizator daniel.grosuDaniel Grosu daniel.grosu Data 12 februarie 2017 10:46:15
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include<bits/stdc++.h>
#define x first
#define pb push_back
#define y second
#define all(a) a.begin(), a.end()
#define l(x) (x<<1)
#define r(x) ((x<<1) | 1)
#define f(x) x>>1
#define lsb(x) (x&(-x))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef VI::iterator vit;
typedef tuple<int,int,int> PIII;
const LL INF=1e6;
const int NMAX=500000;
const LD pi=acos(-1.0);

int n,x,y;

int rec(int k, int i, int j)
{
  if(k==-1)
    return 0;
  int k2=(1<<k), it, jt;

  if(i<=k2 && j<=k2)
  {
    it=j;
    jt=i;
    return rec(k-1, it, jt);
  
  }
  if(i>k2 && j<=k2)
  {
    i=i-k2;
    return k2*k2 + rec(k-1, i, j);
  
  }
  if(i<=k2 && j>k2)
  {
    j=j-k2;
    jt=i;
    it=k2-j+1;
    jt=k2-jt+1;
    return 3*k2*k2 + rec(k-1, it, jt);
  
  }
  if(i>k2 && j>k2)
  {
    i=i-k2;
    j=j-k2;
    return 2*k2*k2 + rec(k-1, i, j);
  }
}

void solve()
{
  cin>>n>>x>>y;
  cout<<rec(n-1, y, x)<<"\n";
}

int main()
{
    cout<<setprecision(6)<<fixed;
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    freopen("fractal.in", "rt", stdin);
    freopen("fractal.out", "wt", stdout);

    int t=1;
    //cin>>t;
    for(int i=1; i<=t; ++i){
      solve();
    }

    cout<<"\n";
    
    return 0;
}