标签:des style blog http color strong
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4420 | Accepted: 2143 |
Description
Input
Output
Sample Input
2 3 yyy yyy yyy 5 wwwww wwwww wwwww wwwww wwwww
Sample Output
0 15
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <math.h> 5 #include <string.h> 6 #include <set> 7 using namespace std; 8 const int MAXN=300; 9 int a[MAXN][MAXN]; 10 int x[MAXN]; 11 bool free_x[MAXN]; 12 inline int gcd(int a,int b) 13 { 14 int t; 15 while(b!=0) 16 { 17 t=b; 18 b=a%b; 19 a=t; 20 } 21 return a; 22 } 23 inline int lcm(int a,int b) 24 { 25 return a/gcd(a,b)*b; 26 } 27 int Gauss(int equ,int var) 28 { 29 int i,j,k; 30 int max_r; 31 int col; 32 col=0; 33 for(k = 0; k < equ && col < var; k++,col++) 34 { 35 max_r=k; 36 for(i=k; i<equ; i++) 37 { 38 if(a[i][col]) 39 { 40 max_r=i; 41 break; 42 } 43 } 44 if(max_r!=k) 45 { 46 for(j=k; j<var+1; j++) swap(a[k][j],a[max_r][j]); 47 } 48 if(a[k][col]==0) 49 { 50 k--; 51 continue; 52 } 53 for(i=0; i<equ; i++) 54 { 55 if(i!=k&&a[i][col]!=0) 56 { 57 for(j=0; j<var+1; j++) 58 { 59 a[i][j]^= a[k][j]; 60 } 61 } 62 } 63 } 64 for (i = k; i < equ; i++) 65 { 66 if (a[i][col] != 0) return 0; 67 } 68 return 1; 69 } 70 int main() 71 { 72 int n,m,t,i,j; 73 cin>>t; 74 char x; 75 while(t--) 76 { 77 memset(a,0,sizeof(a)); 78 cin>>n; 79 m=n*n; 80 for(i=0; i<m; i++) 81 { 82 if(i%n==0)getchar(); 83 x=getchar(); 84 if(x!=‘y‘)a[i][m]=1; 85 } 86 for(i=0; i<m; i++) 87 { 88 a[i][i]=1; 89 if(i-n>=0) 90 a[i][i-n]=1; 91 if(i+n<m) 92 a[i][i+n]=1; 93 if(i%n) 94 a[i][i-1]=1; 95 if((i+1)%n) 96 a[i][i+1]=1; 97 } 98 if(!Gauss(m,m))cout<<"inf"<<endl; 99 else 100 { 101 int ans=0; 102 for(i=0; i<m; i++)ans+=a[i][m]&1; 103 cout<<ans<<endl; 104 } 105 } 106 }
Painter's Problem poj1681 高斯消元法,布布扣,bubuko.com
Painter's Problem poj1681 高斯消元法
标签:des style blog http color strong
原文地址:http://www.cnblogs.com/ERKE/p/3835418.html