Cod sursa(job #460002)

Utilizator nicolaetitus12Nicolae Titus nicolaetitus12 Data 31 mai 2010 22:20:16
Problema Fractal Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <stdio.h>

int f(int k,int x,int y)
{if(k==1)
 { if(x==1)
   {  if(y==1)
      {  return 0;
      }
      else
      {  return 3;
      }
   }
   else
   {  if(y==1)
      {  return 1;
      }
      else
      {  return 2;
      }
   }
 }
 
 int p;
 p=1<<(k-1);
 
 if(x>p)
 {if(y>p)
  {return 2*p*p+f(--k,x-p,y-p);
  }
  else
  {return 3*p*p+f(--k,y,2*p-x);
  }
 }
 else
 {if(y>p)
  {return p*p+f(--k,x,y-p);
  }
  else
  {return f(--k,y,x);
  }
 }
}

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

 scanf("%d %d %d",&k,&x,&y);
 printf("%d ", f(k,x,y));
 
 return 0;
}