daily pastebin goal
68%
SHARE
TWEET

Zadanie_3

a guest Mar 20th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void Xdrzewo(int n, int t, int T[], int TAG[], int MAX[], int X[]);
  6. void out(int tab[], int n);
  7. void One2subset(int one, int SET[], int left, int right);
  8.  
  9. int main()
  10. {
  11.     //GENEROWANIE X-sekwencji 010101010101
  12.     int n,t;
  13.     cout<<"Prosze podac liczbe wierzcholkow wewnetrznych n: ";
  14.     cin>> n;
  15.     cout<<"Prosze podac liczbe potomkow t: ";
  16.     cin>> t;
  17.     int *T=new int[n+1];
  18.     int *TAG=new int[n+1];
  19.     int *MAX=new int[n+1];
  20.     int *X=new int[n*t+1];
  21.     Xdrzewo(n,t,T,TAG,MAX,X);
  22.     //system ("pause");
  23.     return 0;
  24.  
  25.     delete [] T;
  26.     delete [] TAG;
  27.     delete [] MAX;
  28.     delete [] X;
  29. }
  30. void Xdrzewo(int n, int t, int T[], int TAG[], int MAX[], int X[])
  31. {
  32.     int ind=1;
  33.     int s=1;
  34.     for(int i=1; i<=n;i++)
  35.     {
  36.         MAX[i]=(i-1)*(t-1)+1;
  37.     }
  38.     One2subset(s,T,ind,n);
  39.     One2subset(0,TAG,ind,n);
  40.     One2subset(1,X,ind,n);
  41.     One2subset(0,X,n+1,n*t);
  42.     out(X,n*t);
  43.     ind=n;
  44.     while(ind>1)
  45.     {
  46.         if(T[ind]<MAX[ind])
  47.         {
  48.             s=T[ind]+1;
  49.             One2subset(s,T,ind,n);
  50.             One2subset(0,X,T[ind-1]+ind-1,n*t);
  51.             One2subset(1,X,T[ind]+ind-1,T[ind]+n-1);
  52.             if(s==MAX[ind]) One2subset(1,TAG,ind,ind);
  53.             if(ind<n) One2subset(0,TAG,ind+1,n);
  54.             out(X,n*t);
  55.             ind=n;
  56.         }
  57.         else
  58.         {
  59.             ind--;
  60.         }
  61.     }
  62. }
  63. void out(int tab[], int n){
  64.     for(int i=1;i<=n;i++)
  65.     {
  66.         cout<<tab[i]<<" ";
  67.     }
  68.     cout<<endl;
  69.     }
  70.  
  71. void One2subset(int one,int SET[],int left,int right)
  72. {
  73.     for(int i=left;i<=right;i++)
  74.     {
  75.         SET[i]=one;
  76.     }
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top