Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- int To(int a, int b, int c, int d, int s)
- {
- if (s == 1)
- {
- return a*c + a*(c+1);
- }
- if (s == 2)
- {
- return b*(c+1)*d + (b+1)*c*(d+1);
- }
- if (s == 3)
- {
- 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) ;
- }
- }
- int T1(int a, int b, int c, int d, int s)
- {
- if (s == 1)
- {
- return a*c + a*(c-1);
- }
- if (s == 2)
- {
- return b*(c-1)*d + (b-1)*c*(d-1);
- }
- if (s == 3)
- {
- 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) ;
- }
- }
- int Tm(int s, int mas[][4])
- {int a,b,c,d;
- int i,j;
- if (s == 1)
- { i=0; j=3;
- a=mas[i][j];
- c=mas[i+1][j];
- int k1, k2, l1, l2, gg;
- if(c==1){
- k1=a*c + a*(c-1);
- } else { k1=a*c + a*(c+1); }
- a=mas[i][j-1];
- c=mas[i+1][j-1];
- if(c==1){
- k2=a*c + a*(c-1);
- } else { k2=a*c + a*(c+1); }
- a=mas[i][j-2];
- c=mas[i+1][j-2];
- if(c==1){
- l1=a*c + a*(c-1);
- } else { l1=a*c + a*(c+1); }
- a=mas[i][j-3];
- c=mas[i+1][j-3];
- if(c==1){
- l2=a*c + a*(c-1);
- } else { l2=a*c + a*(c+1); }
- if(((k1-l1) >= 0)&&((k2 - l2 ) >= 0))
- {return 1;} else {return 0;}
- }
- if (s == 2)
- {
- b*(c-1)*d + (b-1)*c*(d-1);
- }
- if (s == 3)
- {
- 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) ;
- }
- }
- int main()
- {
- int s;
- int f1[2][4];
- int f2[3][8];
- int f3[4][16];
- int i,j,n,m,k,p,c;
- n=4;
- m=16;
- int a[5][17];
- for(i=1;i<=n;i++)
- for(j=1;j<=m; j++)
- a[i][j]=0;
- for(j=1;j<=n;j++)
- {
- k=m/(pow(2,j));
- p=0;
- c=0;
- for(i=k+1;i<=m; i++)
- {
- if(p<k)
- {
- a[j][i]=1;
- p++;
- }
- else if(c<k-1)
- {
- a[j][i]=0;
- c++;
- }
- else
- {
- p=0;
- c=0;
- }
- }
- }
- for(j=1;j<=m;j++)
- {
- for(i=1;i<=n; i++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- cout << " f1 = AC + A!C";
- cout << " f2 = B!CD + !BC!D";
- cout << " f3 = !A !B !C !D + !A !B C D + !A B! C D + !A B C !D";
- for (j=0; j<4; j++){
- for (i=0; i<2; i++){
- f1[i][j] = a[i+3][j+1];}
- }
- cout << endl;
- for (j=0; j<4; j++){
- for (i=0; i<2; i++){
- cout <<f1[i][j]; } cout<<endl;}
- for (j=0; j<8; j++){
- for (i=0; i<3; i++){
- f2[i][j] = a[i+2][j+1];}}
- cout << endl;
- for (j=0; j<8; j++){
- for (i=0; i<3; i++){
- cout <<f2[i][j]; } cout<<endl;}
- for (j=0; j<16; j++){
- for (i=0; i<4; i++){
- f3[i][j] = a[i+1][j+1];}}
- cout << endl;
- for (j=0; j<16; j++){
- for (i=0; i<4; i++){
- cout <<f3[i][j]; } cout<<endl;}
- s=1;
- cout<< "f1 (To) =" << To(0,0,0,0,s)<<endl;
- s=2;
- cout<< "f2 (To) =" <<To(0,0,0,0,s)<<endl;
- s=3;
- cout<< "f3 (To) =" <<To(0,0,0,0,s)<<endl;
- s=1;
- cout<< "f1 (To) =" << T1(1,1,1,1,s)<<endl;
- s=2;
- cout<< "f2 (To) =" << T1(1,1,1,1,s)<<endl;
- s=3;
- cout<< "f3 (To) =" << T1(1,1,1,1,s)<<endl;
- s=1;
- cout << Tm(s,f1);
- s=2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement