Guest User

Untitled

a guest
Aug 9th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int leftside[5][10]; //l[0][i]=coefficient of a_i, [1]=b_i, [2]=c_i,[3]=d_i,[4]=x_i
  5. int rightside[5][10];
  6. int l[5][10];
  7. int r[5][10];
  8. void convert(vector<int> &v,int A[][10]){
  9.     for (int i=0;i<v.size()-1;i++){
  10.         int x=v[i],y=v[i+1];
  11.         if (x<y){
  12.             A[4][y]++,A[4][x]--;
  13.             A[3][x]++,A[0][y]++;
  14.         }
  15.         else{
  16.             A[4][x]++,A[4][y]--;
  17.             A[2][x]++,A[1][y]++;
  18.         }
  19.     }
  20. }
  21. void cancel(int A[][10],int B[][10]){
  22.     for (int i=0;i<5;i++) for (int j=1;j<=5;j++) B[i][j]-=A[i][j];
  23. }
  24. void print(int A[][10]){
  25.     for (int i=0;i<5;i++){
  26.         for (int j=1;j<=5;j++) cout<<A[i][j]<<' '; cout<<endl;
  27.     }
  28. }
  29. int main(){
  30.     freopen("readable.txt","w",stdout);
  31.     for (int s=1;s<=5;s++) for (int e=1;e<=5;e++) if(e!=s) {
  32.         memset(leftside,0,sizeof leftside); memset(rightside,0,sizeof rightside);
  33.         memset(l,0,sizeof l), memset(r,0,sizeof r);
  34.         vector<int> v;
  35.         for (int i=1;i<=5;i++) if ((i!=s)&&(i!=e)) v.push_back(i);
  36.         int a=v[0],b=v[1],c=v[2];
  37.         //KNOW X(s,a,b,e)<=X(s,b,a,e)
  38.         vector<int> path={s,a,b,e};
  39.         cout<<s<<" -> "<<e<<endl;
  40.         convert(path,leftside);
  41.         vector<int> rpath={s,b,a,e};
  42.         convert(rpath,rightside);
  43.         cancel(leftside,rightside);
  44.         print(rightside);
  45.         cout<<endl;
  46.         for (int p=0;p<3;p++){
  47.             memset(l,0,sizeof l);
  48.             vector<int> opt;
  49.             if (p==0) opt={s,a,b,c,e};
  50.             if (p==1) opt={s,a,c,b,e};
  51.             if (p==2) opt={s,c,a,b,e};
  52.             convert(opt,l);
  53.             for (int q=0;q<3;q++){
  54.                 memset(r,0,sizeof r);
  55.                 vector<int> oth;
  56.                 if (q==0) oth={s,b,a,c,e};
  57.                 if (q==1) oth={s,b,c,a,e};
  58.                 if (q==2) oth={s,c,b,a,e};
  59.                 convert(oth,r);
  60.                 cancel(l,r);
  61.                 bool good=true;
  62.                 for (int i=0;i<5;i++) for (int j=1;j<=5;j++) if (rightside[i][j]!=r[i][j]) good=false;
  63.                 bool allZero=true;
  64.                 for (int i=0;i<5;i++) for (int j=1;j<=5;j++) if (r[i][j]!=0) allZero=false;
  65.                 if ((good)||(allZero)){
  66.                     for (int x:opt) cout<<x<<" "; cout<<"vs ";
  67.                     for (int x:oth) cout<<x<<" "; cout<<endl;
  68.                     print(r); cout<<endl;
  69.                 }
  70.             }
  71.         }
  72.     }
  73.     return 0;
  74. }
Add Comment
Please, Sign In to add comment