Cod sursa(job #451128)

Utilizator SuperSuper Smecher Super Data 9 mai 2010 03:31:58
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <iostream>
#include <fstream>
using namespace std;

#include<stdio.h>

int main()
{
   int mL[4][4] = {{0, 3, 4, 5}, {1, 2, 7, 6}, {14, 13, 8, 9}, {15, 12, 11, 10}};
   int mU[4][4] = {{0, 1, 14, 15}, {3, 2, 13, 12}, {4, 7, 8, 11}, {5, 6, 9, 10}};
   freopen("fractal.in","r",stdin);
   freopen("fractal.out","w",stdout);
   
   int k =0;
   scanf("%i",&k);
   int c = 0, l = 0;
   scanf("%i",&c);
   scanf("%i",&l);
   
   int n = 2<<(k-1);
   int rez = 0, nm = 0;

   int up = false, left = false;
   if(n>7)
   {
     while(n/2 >= 4)
     {
      if( l > n/2)
      {
        up = false;
      }
      else
      {
        up = true;
      }
      if( c > n/2)
      {
        left = false;
      }
      else
      {
        left = true;
      }
      
      if(up == false && left == true)
      {
        rez += 16;
      }
      if(up == false && left == false)
      {
        rez += 16 + 16;
      }
      if(up == true && left == false)
      {
        rez += 16 + 16 + 16;
      }
      n /= 2;
      nm += n;
     }
   }
      
  //cout <<"left="<<left<<"up="<<up<<endl;
  
  if(l <= 4 && c <= 4)
   {
    rez += mU[l-1][c-1];
   }
   else
   {
    if(l>nm) l = l-nm;
    if(c>nm) c = c-nm;
    l -= 1;
    c -= 1;
    if(up == false)
    {
      rez += mU[l][c];
    }
    else
    {
      if(left == true)
      {
        rez += mU[l][c];
      }
      else 
      {
        rez += mU[l][c]; //imagine
      }
    }
   }
   
   printf("%i",rez);
   
   return 0;
}