Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int n ,tot[MAX],pos[MAX]; double edge[MAX][MAX],res[MAX];vector<pii>v[MAX];
- int gauss(int row,int col)
- {
- mem(pos,-1);
- int free_var = 0;
- for(int i = 1,j = 1;i<=row,j<=col;i++,j++)
- {
- int mx = i;
- for(int k = i;k<=row;k++)if(abs(edge[mx][j])<abs(edge[k][j])) mx = k;
- if(abs(edge[mx][j])>EPS)
- {
- pos[j] = i;
- for(int l = j;l<=col;l++)swap(edge[i][l],edge[mx][l]);
- for(int l = 1;l<=row;l++)
- {
- if(l==i)continue;
- double xx = edge[l][j] / edge[i][j];
- for(int pp = j;pp<=col;pp++)edge[l][pp]-=(edge[i][pp]*xx);
- }
- }
- }
- for(int l = 1;l<col;l++)
- {
- if(pos[l]==-1)free_var++;
- else res[l] = edge[pos[l]][col]/edge[pos[l]][l];
- }
- for(int i = 1;i<=row;i++)
- {
- double val = 0.0;
- for(int j = 1;j<col;j++)val+=(res[j]*edge[i][j]);
- if(abs(val - edge[i][col])>EPS)return -1;
- }
- return free_var;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement