Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.99 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7.  int Ts(int mass[][16]) {
  8.     int k = 0; int j=0;
  9.     for (int i = 0; i < 16; i++) {
  10.         if (mass[j][i] == 1) {
  11.             k++;
  12.         }
  13.     }
  14.     if (k != 8) {
  15.         return 0;
  16.     }
  17.     else {
  18.         k = 15;
  19.         for (int i = 0; i < 8;i++) {
  20.             if (mass[j][i] == mass[j][k]) {
  21.                 return 0;
  22.             }
  23.             k--;
  24.         }
  25.     }
  26.     return 1;
  27. }
  28.  
  29. int Tl(int mass[][16]) {
  30.     bool arr[16][16];
  31.     for (int i = 0; i < 16; i++) {
  32.         arr[0][i] = mass[i];
  33.     }
  34.     for (int i = 1; i < 16; i++) {
  35.         for (int j = 0; j < 15; j++) {
  36.             if (arr[i - 1][j] != arr[i - 1][j + 1]) {
  37.                 arr[i][j] = 1;
  38.             }
  39.             else {
  40.                 arr[i][j] = 0;
  41.             }
  42.         }
  43.     }
  44.     for (int i = 0; i < 16; i++) {
  45.         if (arr[i][0] == 1) {
  46.             if (i == 0 || i == 1 || i == 2 || i == 4 || i == 8) {
  47.             }
  48.             else {
  49.                 return 0;
  50.             }
  51.         }
  52.     }
  53.     return 1;
  54. }
  55.  
  56. int To(int a, int b, int c, int d, int s)
  57. {
  58.  if (s == 1)
  59.  {
  60. return  a*c + a*(c+1);
  61.  }
  62.  
  63.  if (s == 2)
  64.  {
  65.      return b*(c+1)*d + (b+1)*c*(d+1);
  66.  }
  67.  if (s == 3)
  68.  {
  69.    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)   ;
  70.  }
  71. }
  72.  
  73. int T1(int a, int b, int c, int d, int s)
  74. {
  75.  if (s == 1)
  76.  {
  77. return  a*c + a*(c-1);
  78.  }
  79.  
  80.  if (s == 2)
  81.  {
  82.      return b*(c-1)*d + (b-1)*c*(d-1);
  83.  }
  84.  if (s == 3)
  85.  {
  86.    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)   ;
  87.  }
  88. }
  89.  
  90.  
  91. int Tm(int s, int mas[][16])
  92. {int a,b,c,d;
  93. int i,j;
  94.  
  95.  if (s == 1)
  96.  { i=0; j=3;
  97.      a=mas[i][j];
  98.     c=mas[i+1][j];
  99.      int k1, k2, l1, l2;
  100.      if(c==1){
  101.         k1=a*c + a*(c-1);
  102.      } else { k1=a*c + a*(c+1); }
  103.         a=mas[i][j-1];
  104.         c=mas[i+1][j-1];
  105.    
  106.         if(c==1){
  107.         k2=a*c + a*(c-1);
  108.      } else { k2=a*c + a*(c+1); }
  109.          a=mas[i][j-2];
  110.         c=mas[i+1][j-2];
  111.          if(c==1){
  112.         l1=a*c + a*(c-1);
  113.      } else { l1=a*c + a*(c+1); }
  114.        a=mas[i][j-3];
  115.         c=mas[i+1][j-3];
  116.      
  117.      if(c==1){
  118.         l2=a*c + a*(c-1);
  119.      } else { l2=a*c + a*(c+1); }
  120.      
  121.      
  122.      if(((k1-l1) >= 0)&&((k2 - l2 ) >= 0))
  123.         {return 1;} else {return 0;}
  124.  }
  125.   if (s == 2)
  126.  {  int k1, k2, l1, l2, k3, k4, l3, l4;
  127.   i=0; j=7;
  128.  b=mas[i][j];
  129.     c=mas[i+1][j];
  130.         d=mas[i+2][j];
  131.       k1=b*(c-1)*d + (b-1)*c*(d-1);  b=mas[i][j-1]; c=mas[i+1][j-1]; d=mas[i+2][j-1];
  132.        k2=b*(c-1)*d + (b-1)*c*(d+1);    b=mas[i][j-2]; c=mas[i+1][j-2]; d=mas[i+2][j-2];
  133.         k3=b*(c+1)*d + (b-1)*c*(d-1);   b=mas[i][j-3]; c=mas[i+1][j-3]; d=mas[i+2][j-3];
  134.          k4=b*(c+1)*d + (b-1)*c*(d+1);  b=mas[i][j-4]; c=mas[i+1][j-4]; d=mas[i+2][j-4];
  135.           l1=b*(c+1)*d + (b+1)*c*(d+1); b=mas[i][j-5]; c=mas[i+1][j-5]; d=mas[i+2][j-5];
  136.            l2=b*(c+1)*d + (b+1)*c*(d+1);  b=mas[i][j-6]; c=mas[i+1][j-6]; d=mas[i+2][j-6];
  137.             l3=b*(c-1)*d + (b+1)*c*(d+1);  b=mas[i][j-7]; c=mas[i+1][j-7]; d=mas[i+2][j-7];
  138.              l4=b*(c-1)*d + (b+1)*c*(d-1);
  139.     if(((k1-l1) >= 0)&&((k2 - l2 ) >= 0)&&((k3-l3) >= 0)&&((k4 - l4 ) >= 0))
  140.     {return 1;} else {return 0;}
  141.  }
  142.  if (s == 3)
  143.  { int k1, k2, l1, l2, k3, k4, l3, l4, k5, k6, l5, l6, k7, k8, l7, l8;
  144.  int a,b,c,d;
  145.  i=0; j=15;
  146.  a=mas[i][j];
  147.     b=mas[i+1][j];
  148.         c=mas[i+2][j];
  149.             d=mas[i+2][j];
  150.    k1=(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);  a=mas[i][j-1]; b=mas[i+1][j-1]; c=mas[i+2][j-1]; d=mas[i+3][j-1];
  151.    k2=(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);  a=mas[i][j-2]; b=mas[i+1][j-2]; c=mas[i+2][j-2]; d=mas[i+3][j-2];
  152.    k3=(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);  a=mas[i][j-3]; b=mas[i+1][j-3]; c=mas[i+2][j-3]; d=mas[i+3][j-3];
  153.    k4=(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);  a=mas[i][j-4]; b=mas[i+1][j-4]; c=mas[i+2][j-4]; d=mas[i+3][j-4];
  154.    k5=(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);  a=mas[i][j-5]; b=mas[i+1][j-5]; c=mas[i+2][j-5]; d=mas[i+3][j-5];
  155.    k6=(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);  a=mas[i][j-6]; b=mas[i+1][j-6]; c=mas[i+2][j-6]; d=mas[i+3][j-6];
  156.    k7=(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);  a=mas[i][j-7]; b=mas[i+1][j-7]; c=mas[i+2][j-7]; d=mas[i+3][j-7];
  157.    k8=(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);  a=mas[i][j-8]; b=mas[i+1][j-8]; c=mas[i+2][j-8]; d=mas[i+3][j-8];
  158.    l1=(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);  a=mas[i][j-9]; b=mas[i+1][j-9]; c=mas[i+2][j-9]; d=mas[i+3][j-9];
  159.    l2=(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);  a=mas[i][j-10]; b=mas[i+1][j-10]; c=mas[i+2][j-10]; d=mas[i+3][j-10];
  160.    l3=(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);  a=mas[i][j-11]; b=mas[i+1][j-11]; c=mas[i+2][j-11]; d=mas[i+3][j-11];
  161.    l4=(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);  a=mas[i][j-12]; b=mas[i+1][j-12]; c=mas[i+2][j-12]; d=mas[i+3][j-12];
  162.    l5=(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);  a=mas[i][j-13]; b=mas[i+1][j-13]; c=mas[i+2][j-13]; d=mas[i+3][j-13];
  163.    l6=(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);  a=mas[i][j-14]; b=mas[i+1][j-14]; c=mas[i+2][j-14]; d=mas[i+3][j-14];
  164.    l7=(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);  a=mas[i][j-15]; b=mas[i+1][j-15]; c=mas[i+2][j-15]; d=mas[i+3][j-15];
  165.    l8=(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);
  166.    if(((k1-l1) >= 0)&&((k2 - l2 ) >= 0)&&((k3-l3) >= 0)&&((k4 - l4 ) >= 0)&&((k5-l5) >= 0)&&((k6 - l6 ) >= 0)&&((k7-l7) >= 0)&&((k8 - l8) >= 0))
  167.    {return 1;} else {return 0;}
  168.  }
  169.  
  170. }
  171.  
  172.  
  173. int main()
  174. {
  175.     int s;
  176.     int f1[4][16];
  177.     int f2[4][16];
  178.     int f3[4][16];
  179.     int i,j,n,m,k,p,c;
  180.     n=4;
  181.     m=16;
  182.     int a[5][17];
  183.      for(i=1;i<=n;i++)
  184.         for(j=1;j<=m; j++)
  185.             a[i][j]=0;
  186.  
  187.     for(j=1;j<=n;j++)
  188.         {
  189.             k=m/(pow(2,j));
  190.             p=0;
  191.             c=0;
  192.             for(i=k+1;i<=m; i++)
  193.             {
  194.                 if(p<k)
  195.                 {
  196.                     a[j][i]=1;
  197.                     p++;
  198.                 }
  199.                 else if(c<k-1)
  200.                 {
  201.                     a[j][i]=0;
  202.                     c++;
  203.                 }
  204.                 else
  205.                 {
  206.                     p=0;
  207.                     c=0;
  208.                 }
  209.  
  210.             }
  211.  
  212.         }
  213.  
  214.  
  215.      for (j=0; j<4; j++){
  216.  for (i=0; i<2; i++){
  217.  f1[i][j] = a[i+3][j+1];}
  218.  }
  219.  
  220.  
  221.  for (j=0; j<8; j++){
  222.  for (i=0; i<3; i++){
  223.  f2[i][j] = a[i+2][j+1];}}
  224.  
  225.  
  226.  
  227.  for (j=0; j<16; j++){
  228.  for (i=0; i<4; i++){
  229.  f3[i][j] = a[i+1][j+1];}}
  230.  
  231.  
  232.  
  233. s=1;
  234.  cout <<"T0    T1    Tm    Tl    Ts"<<endl;
  235.  
  236.  if(To(0,0,0,0,s) == 1){
  237.     cout<<" -"; }
  238.     else {cout<<" +";}
  239.     if(T1(1,1,1,1,s) == 1){
  240.     cout<<"     +"; }
  241.     else {cout<<"     -";}
  242.     if(Tm(s,f1) == 1){
  243.     cout<<"     +"; }
  244.     else {cout<<"     -";}
  245.      if(Tl(f1) == 1){
  246.     cout<<"    +"; }
  247.     else {cout<<"    -";}
  248.      if(Ts(f1) == 1){
  249.     cout<<"     +"<<endl; s++;}
  250.     else {cout<<"     -"<<endl; s++;}
  251.    
  252.     if(To(0,0,0,0,s) == 1){
  253.     cout<<" -"; }
  254.     else {cout<<" +";}
  255.     if(T1(1,1,1,1,s) == 1){
  256.     cout<<"     +"; }
  257.     else {cout<<"     -";}
  258.     if(Tm(s,f2) == 1){
  259.     cout<<"     +"; }
  260.     else {cout<<"     -";}
  261.      if(Tl(f2) == 1){
  262.     cout<<"    +"; }
  263.     else {cout<<"    -";}
  264.      if(Ts(f2) == 1){
  265.     cout<<"     +"<<endl; s++;}
  266.     else {cout<<"     -"<<endl; s++;}
  267.    
  268.     if(To(0,0,0,0,s) == 1){
  269.     cout<<" -"; }
  270.     else {cout<<" +";}
  271.     if(T1(1,1,1,1,s) == 1){
  272.     cout<<"     +"; }
  273.     else {cout<<"     -";}
  274.     if(Tm(s,f3) == 1){
  275.     cout<<"     +"; }
  276.     else {cout<<"     -";}
  277.      if(Tl(f3) == 1){
  278.     cout<<"    +"; }
  279.     else {cout<<"    -";}
  280.      if(Ts(f3) == 1){
  281.     cout<<"     +"<<endl; }
  282.     else {cout<<"     -"<<endl; }
  283.  
  284.  
  285.     return 0;
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement