poj 1222 高斯消元(改改模板)
先贴一下大牛博客里面的高斯消元专题 http://blog.csdn.net/qiqijianglu/article/details/7945197
然后这个题构造矩阵有点意思,比较有想法,构造出来就直接套模板了
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <stack> 5 #include <queue> 6 #include <map> 7 #include <algorithm> 8 #include <vector> 9 #include <cstdlib> 10 #include <cmath> 11 12 using namespace std; 13 14 const int maxn = 1000005; 15 16 typedef long long LL; 17 18 int A[35][35]; 19 int ans[35]; 20 21 void gauss(int m,int n) //m个方程,n个变量 22 { 23 int i,j,k,r,u; 24 for(i=0,j=0;i<m&&j<n;j++){ //当前处理i个方程j个变量 25 r = i; 26 for(k = i;k < m;k++){ 27 if(A[k][j]){ 28 r = k; 29 break; 30 } 31 } 32 if(A[r][j]){ 33 for(k = 0;k <= n;k++) swap(A[r][k],A[i][k]); 34 for(u = 0;u < m;u++){ 35 if(u!=i && A[u][j]) for(k = i;k <= n;k++) A[u][k] ^= A[i][k]; 36 } 37 i++; 38 } 39 40 41 } 42 for(int i=0;i<30;i++){ 43 ans[i] = A[i][30]; 44 } 45 46 47 } 48 49 int main() 50 { 51 int t; 52 scanf("%d",&t); 53 int cas = 0; 54 while(t--){ 55 cas++; 56 memset(A,0,sizeof(A)); 57 for(int i=0;i<30;i++){ 58 scanf("%d",&A[i][30]); 59 //ans[i] = 0; 60 } 61 int x,xx,y,yy; //构造矩阵 62 for(int i=0;i<30;i++){ 63 x = i/6; 64 y = i%6; 65 for(int j=0;j<30;j++){ 66 xx = j/6; 67 yy = j%6; 68 if((abs(x - xx)+abs(y - yy)) <= 1) A[i][j] = 1; 69 else A[i][j] = 0; 70 } 71 } 72 gauss(30,30); 73 printf("PUZZLE #%d\n",cas); 74 for(int i=0;i<30;i++){ 75 printf("%d",ans[i]); 76 if((i+1)%6==0) printf("\n"); 77 else printf(" "); 78 } 79 } 80 return 0; 81 }
It is loneliness that make you different,not gregariousness