Advertisement
mihaimarcel21

Cochilie

Mar 24th, 2021
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define left Stanga
  3. #define right Dreapta
  4. using namespace std;
  5. ifstream fin("cochilie.in");
  6. ofstream fout("cochilie.out");
  7. int v[832040];
  8. int left, right;
  9. int Fibo[32];
  10. int line;
  11. void divide(int step)
  12. {
  13.     if(step<0)
  14.         return;
  15.     if(step%4==0)
  16.     {
  17.         if(line<=Fibo[step])
  18.         {
  19.             while(left<=right)
  20.                 v[left++]=step+1;
  21.             return;
  22.         }
  23.         line-=Fibo[step];
  24.     }
  25.     if(step%4==1)
  26.     {
  27.         for(int i=0; i<Fibo[step]; i++)
  28.             v[right--]=step+1;
  29.     }
  30.     if(step%4==2)
  31.     {
  32.         if(line>Fibo[step-1])
  33.         {
  34.             while(left<=right)
  35.                 v[left++]=step+1;
  36.             return;
  37.         }
  38.     }
  39.     if(step%4==3)
  40.     {
  41.         for(int i=0; i<Fibo[step]; i++)
  42.             v[left++]=step+1;
  43.     }
  44.     divide(step-1);
  45.     return;
  46. }
  47. int main()
  48. {
  49.     int c,n,p;
  50.     fin>>c;
  51.     fin>>n;
  52.     int len[2]={1,1};
  53.     p=1;
  54.     Fibo[0]=Fibo[1]=1;
  55.     for(int i=1; i<n; i++)
  56.     {
  57.         len[p]+=len[p^1];
  58.         Fibo[i+1]=len[p];
  59.         p^=1;
  60.     }
  61.     if(c==1)
  62.     {
  63.         fout<<len[0]<<' '<<len[1] <<'\n';
  64.     }
  65.     else
  66.     {
  67.         fin>>line;
  68.         n--;
  69.         left=0;
  70.         right=len[1]-1;
  71.         divide(n);
  72.         for(int i=0; i<len[1]; i++)
  73.             fout<<v[i]<<' ';
  74.         fout<<'\n';
  75.     }
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement