Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.48 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7.  
  8. int To(int a, int b, int c, int d, int s)
  9. {
  10.  if (s == 1)
  11.  {
  12. return  a*c + a*(c+1);
  13.  }
  14.  
  15.  if (s == 2)
  16.  {
  17.      return b*(c+1)*d + (b+1)*c*(d+1);
  18.  }
  19.  if (s == 3)
  20.  {
  21.    return (a+1)*(b+1)*(c+1)*(d+1) + (a+1)*(b+1)*c*d + (a+1)*b*(c+1)*d + (a+1)*b*c*(d+1)   ;
  22.  }
  23. }
  24.  
  25. int T1(int a, int b, int c, int d, int s)
  26. {
  27.  if (s == 1)
  28.  {
  29. return  a*c + a*(c-1);
  30.  }
  31.  
  32.  if (s == 2)
  33.  {
  34.      return b*(c-1)*d + (b-1)*c*(d-1);
  35.  }
  36.  if (s == 3)
  37.  {
  38.    return (a-1)*(b-1)*(c-1)*(d-1) + (a-1)*(b-1)*c*d + (a-1)*b*(c-1)*d + (a-1)*b*c*(d-1)   ;
  39.  }
  40. }
  41.  
  42.  
  43. int Tm(int s, int mas[][4])
  44. {int a,b,c,d;
  45. int i,j;
  46.  
  47.  if (s == 1)
  48.  { i=0; j=3;
  49.      a=mas[i][j];
  50.     c=mas[i+1][j];
  51.      int k1, k2, l1, l2, gg;
  52.      if(c==1){
  53.         k1=a*c + a*(c-1);
  54.      } else { k1=a*c + a*(c+1); }
  55.         a=mas[i][j-1];
  56.         c=mas[i+1][j-1];
  57.    
  58.         if(c==1){
  59.         k2=a*c + a*(c-1);
  60.      } else { k2=a*c + a*(c+1); }
  61.          a=mas[i][j-2];
  62.         c=mas[i+1][j-2];
  63.          if(c==1){
  64.         l1=a*c + a*(c-1);
  65.      } else { l1=a*c + a*(c+1); }
  66.        a=mas[i][j-3];
  67.         c=mas[i+1][j-3];
  68.      
  69.      if(c==1){
  70.         l2=a*c + a*(c-1);
  71.      } else { l2=a*c + a*(c+1); }
  72.      
  73.      
  74.      if(((k1-l1) >= 0)&&((k2 - l2 ) >= 0))
  75.         {return 1;} else {return 0;}
  76.  }
  77.   if (s == 2)
  78.  {
  79.       b*(c-1)*d + (b-1)*c*(d-1);
  80.  }
  81.  if (s == 3)
  82.  {
  83.    return (a-1)*(b-1)*(c-1)*(d-1) + (a-1)*(b-1)*c*d + (a-1)*b*(c-1)*d + (a-1)*b*c*(d-1)   ;
  84.  }
  85.  
  86. }
  87.  
  88.  
  89. int main()
  90. {
  91.     int s;
  92.     int f1[2][4];
  93.     int f2[3][8];
  94.     int f3[4][16];
  95.     int i,j,n,m,k,p,c;
  96.     n=4;
  97.     m=16;
  98.     int a[5][17];
  99.      for(i=1;i<=n;i++)
  100.         for(j=1;j<=m; j++)
  101.             a[i][j]=0;
  102.  
  103.     for(j=1;j<=n;j++)
  104.         {
  105.             k=m/(pow(2,j));
  106.             p=0;
  107.             c=0;
  108.             for(i=k+1;i<=m; i++)
  109.             {
  110.                 if(p<k)
  111.                 {
  112.                     a[j][i]=1;
  113.                     p++;
  114.                 }
  115.                 else if(c<k-1)
  116.                 {
  117.                     a[j][i]=0;
  118.                     c++;
  119.                 }
  120.                 else
  121.                 {
  122.                     p=0;
  123.                     c=0;
  124.                 }
  125.  
  126.             }
  127.  
  128.         }
  129.     for(j=1;j<=m;j++)
  130.     {
  131.         for(i=1;i<=n; i++)
  132.         {
  133.             cout << a[i][j] << " ";
  134.         }
  135.  
  136.     cout << endl;
  137.     }
  138.  
  139.  
  140. cout << " f1 = AC + A!C";
  141.  cout << " f2 = B!CD + !BC!D";
  142.   cout << " f3 = !A !B !C !D + !A !B C D + !A B! C D + !A B C !D";
  143.  
  144.  
  145.  
  146.      for (j=0; j<4; j++){
  147.  for (i=0; i<2; i++){
  148.  f1[i][j] = a[i+3][j+1];}
  149.  }
  150.  cout << endl;
  151. for (j=0; j<4; j++){
  152.  for (i=0; i<2; i++){
  153.      cout <<f1[i][j]; } cout<<endl;}
  154.  
  155.  for (j=0; j<8; j++){
  156.  for (i=0; i<3; i++){
  157.  f2[i][j] = a[i+2][j+1];}}
  158.  
  159.  cout << endl;
  160. for (j=0; j<8; j++){
  161.  for (i=0; i<3; i++){
  162.      cout <<f2[i][j]; } cout<<endl;}
  163.  
  164.  for (j=0; j<16; j++){
  165.  for (i=0; i<4; i++){
  166.  f3[i][j] = a[i+1][j+1];}}
  167.  
  168.  
  169.  cout << endl;
  170. for (j=0; j<16; j++){
  171.  for (i=0; i<4; i++){
  172.      cout <<f3[i][j]; } cout<<endl;}
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  s=1;
  179.  cout<< "f1 (To) =" << To(0,0,0,0,s)<<endl;
  180.  s=2;
  181.  cout<< "f2 (To) =" <<To(0,0,0,0,s)<<endl;
  182.  s=3;
  183.  cout<< "f3 (To) =" <<To(0,0,0,0,s)<<endl;
  184.  s=1;
  185.  cout<< "f1 (To) =" << T1(1,1,1,1,s)<<endl;
  186.  s=2;
  187.  cout<< "f2 (To) =" << T1(1,1,1,1,s)<<endl;
  188.  s=3;
  189.  cout<< "f3 (To) =" << T1(1,1,1,1,s)<<endl;
  190.  
  191.  
  192.  s=1;
  193.  cout << Tm(s,f1);
  194.  s=2;
  195.  
  196.  
  197.  
  198.     return 0;
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement