Mathematical---Gaussian elimination POJ 1830

Source: Internet
Author: User

Switching problems problem ' s link:http://poj.org/problem?id=1830

Mean:

Slightly

Analyse:

Slightly augmented matrix: Con[i][j]: If the Operation J,i state change is con[i][j]=1, otherwise con[i][j]=0.

The last augmented matrix should be N (n+1), the last column: The whole state of Bikai, if the same is 0, if the difference is 1;

There are three kinds of final solutions:
1. No solution, there is a row in front of the number of n is 0, the value of the n+1 is not 0;
2. There is no 1th case, the existence of X-line value is all 0, then the number of solutions is 2^x;
3, No 1, 22 cases appear, the only solution, Output 1.

Time Complexity:o (n)

Source Code:

/** This code was made by crazyacking* verdict:accepted* submission date:2015-06-17-22.36* time:0ms* memory:137kb*/#include<queue>#include<cstdio>#include<Set>#include<string>#include<stack>#include<cmath>#include<climits>#include<map>#include<cstdlib>#include<iostream>#include<vector>#include<algorithm>#include<cstring>#defineLL Long Long#defineULL unsigned long Longusing namespacestd;Const intp= -;intCon[p][p];intN;intBeg[p],fin[p];intfunction () {intI,j,k,t,row,col,temp,count=0;  for(row=col=1; row<=n&&col<=n; row++,col++)      {            if(con[row][col]==0)            {                   for(i=row+1; i<=n; i++)                  {                        if(con[i][col]!=0)                        {                               for(j=1; j<=n+1; J + +) {swap (con[row][j],con[i][j]); }                               Break; }                  }            }            if(con[row][col]==0) {row--; Continue; }             for(k=1; k<=n; k++)             {                  if(con[k][col]!=0&&k!=row) {Temp=-(con[k][col]/Con[row][col]);  for(T=col; t<=n+1; t++) {Con[k][t]= (Temp*con[row][t]) +Con[k][t]; }                  }            }      }       for(K=row; k<n+1; k++)            if(con[k][n+1]!=0) {return 0; } if(row==n+1) {return 1; } Else      {            return 1<< (n-row+1); }}intMain () {intT,i,j,x,y; scanf ("%d",&T);  while(t--) {scanf ("%d",&N);  for(i=1; i<=n; i++) {scanf ("%d",&Beg[i]); }             for(i=1; i<=n; i++) {scanf ("%d",&Fin[i]); } scanf ("%d%d",&x,&y); Memset (Con,0,sizeof(Con));  while(x!=0&&y!=0) {Con[y][x]=1; scanf ("%d%d",&x,&y); }             for(i=1; i<=n; i++) {Con[i][i]=1; }             for(i=1; i<=n; i++)            {                  if(beg[i]==Fin[i]) {Con[i][n+1]=0; }                  Else{con[i][n+1]=1; }            }            intPP =function (); if(PP) {printf ("%d\n", pp); }            Else{printf ("Oh,it ' s impossible~!! \ n"); }      }}
View Code

Mathematical---Gaussian elimination POJ 1830

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.