[Gauss] POJ1681 Painter ' s problem

Source: Internet
Author: User

Exactly the same as POJ1222 (http://www.cnblogs.com/Empress/p/4156234.html)

Test instructions is similar, can be painted yourself and up and down five positions in the color

How many times can I paint it all? Cannot output inf

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <climits>5#include <cctype>6#include <cmath>7#include <string>8#include <sstream>9#include <iostream>Ten#include <algorithm> One#include <iomanip> A using namespacestd; -#include <queue> -#include <stack> the#include <vector> -#include <deque> -#include <Set> -#include <map> +typedefLong LongLL; -typedefLong DoubleLD; + Const DoublePi=acos (-1.0); A Const Doubleeps=1e-9; at #defineINF 0x3f3f3f - #defineLson L, M, rt<<1 - #defineRson m+1, R, rt<<1|1 -typedef pair<int,int>PI; -typedef pair<int, PI >PP; - #ifdef _WIN32 in #defineLLD "%i64d" - #else to #defineLLD "%lld" + #endif - //#pragma COMMENT (linker, "/stack:1024000000,1024000000") the //ll Quick (ll A, ll b) {ll ans=1;while (b) {if (b & 1) ans*=a;a=a*a;b>>=1;} return ans;} * //inline int Read () {char ch= "; int ans=0;while (ch< ' 0 ' | | ch> ' 9 ') Ch=getchar (); while (ch<= ' 9 ' && Ch >= ' 0 ') {ans=ans*10+ch-' 0 '; Ch=getchar ();} return ans;} $ //inline void print (LL x) {printf (LLD, x);p UTS ("");Panax Notoginseng //inline void Read (LL &ret) {char c;int sgn; LL bit=0.1;if (C=getchar (), c==eof) return, while (c!= '-' &&c!= '. && (c< ' 0 ' | | C> ' 9 ')) C=getchar (), sgn= (c== '-'), -1:1;ret= (c== '-')? 0: (c ' 0 '); while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret=ret*10+ (c ' 0 '); if (c== "| | c== ' \ n ') {ret*=sgn; return;} while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret+= (c ' 0 ') *bit,bit/=10;ret*=sgn;} -  the Charmp[ -][ -]; + inta[ -][ -], x[ -]; A intN; the BOOLGauss () + { -     intK, col; $      for(k=0, col=0; k<n*n && col<n*n;k++, col++) $     { -         intMaxr=K; -          for(inti=k+1; i<n*n;i++) the             if(ABS (A[i][col]) >ABS (A[maxr][col])) -Maxr=i;Wuyi         if(k!=maxr) the              for(intj=col;j<=n*n;j++) - swap (A[k][j], a[maxr][j]); Wu         if(a[k][col]==0) -         { Aboutk--; $             Continue; -         } -          for(inti=k+1; i<n*n;i++) -             if(A[i][col]) A                  for(intj=col;j<=n*n;j++) +a[i][j]^=A[k][j]; the     } -      for(inti=k;i<n*n;i++) $         if(A[i][col]) the             return false; the      for(inti=n*n-1; i>=0; i--) the     { thex[i]=a[i][n*n]; -          for(intj=i+1; j<n*n;j++) inx[i]^= (A[I][J) &&x[j]); the     } the     return true; About } the intMain () the { the     intT; +scanf"%d", &t); -      while(t--) the     {Bayiscanf"%d", &n); the          for(intI=0; i<n;i++) the              for(intj=0; j<n;j++) -Cin>>Mp[i][j]; -Memset (A,0,sizeof(a)); the          for(intI=0; i<n;i++) the              for(intj=0; j<n;j++) the             { the                 intt=i*n+J; -a[t][t]=1; the                 if(i>0) thea[(I-1) *n+j][t]=1; the                 if(i<n-1)94a[(i+1) *n+j][t]=1; the                 if(j>0) thea[i*n+j-1][t]=1; the                 if(j<n-1)98a[i*n+j+1][t]=1; About                 if(mp[i][j]=='y') -a[t][n*n]=0;101                 Else102a[t][n*n]=1;103             }104         if(Gauss ()) the         {106             intans=0;107              for(intI=0; i<n*n;i++)108                 if(x[i]==1)109ans++; theprintf"%d\n", ans);111         } the         Else113printf"inf\n"); the     } the     return 0; the}
POJ 1681

[gauss]poj1681 Painter ' s problem

Related Article

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.