poj1222 EXTENDED LIGHTS OUT [Gaussian elimination]

Lighting problem. And on a similar, but this is a square, a lamp is operated once after four negated. The goal is to find the least point many times.

Part I forgot to say, a lamp only once or zero times it makes sense to operate, the equivalent of twice took two xor. This is not bullshit you.

The impact of content on an altered, then solving the case, for each coefficient equation is not zero, the first place is a main factor yuan, coefficient is free behind the main yuan yuan, greedy wish taking all 0, then principal component takes 0 or 1 depends on the right side of the equal sign. Recording each lamp operation, regardless of all-zero coefficient equation.

Gone.

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 #define dbg(x) cerr << #x << " = " << x <<endl
 7 using namespace std;
 8 typedef long long ll;
 9 typedef double db;
10 typedef pair<int,int> pii;
11 template<typename T>inline T _min(T A,T B){return A<B?A:B;}
12 template<typename T>inline T _max(T A,T B){return A>B?A:B;}
13 template<typename T>inline char MIN(T&A,T B){return A>B?(A=B,1):0;}
14 template<typename T>inline char MAX(T&A,T B){return A<B?(A=B,1):0;}
15 template<typename T>inline void _swap(T&A,T&B){A^=B^=A^=B;}
16 template<typename T>inline T read(T&x){
17     x=0;int f=0;char c;while(!isdigit(c=getchar()))if(c=='-')f=1;
18     while(isdigit(c))x=x*10+(c&15),c=getchar();return f?x=-x:x;
19 }
20 int A[33],bin[33],ans[33];
21 int T,n=30,x,y,c;
22 inline void preprocess(){
23     for(register int i=1;i<=n;++i){
24         if(i-6>0)A[i]|=bin[i-7];
25         if(i+6<=n)A[i]|=bin[i+5];
26         if(i%6!=1)A[i]|=bin[i-2];
27         if(i%6!=0)A[i]|=bin[i];
28         A[i]|=bin[i-1];
29     }
30 }
31 
32 int main(){//freopen("test.in","r",stdin);freopen("test.ans","w",stdout);
33     for(register int i=0;i<=30;++i)bin[i]=1<<i;
34     read(T);for(register int tt=1;tt<=T;++tt){
35         memset(ans,0,sizeof ans);memset(A,0,sizeof A);
36         for(register int i=1;i<=n;++i)read(x),A[i]|=x<<n;
37         preprocess();
38         for(x=1,c=1;c<=n;++c){
39             for(y=x;y<=n&&!(bin[c-1]&A[y]);++y);
40             if(y==n+1)continue;
41             swap(A[x],A[y]);
42             for(register int l=1;l<=n;++l)if((l^x)&&(A[l]&bin[c-1]))A[l]^=A[x];
43             ++x;
44         }
45         for(register int i=1;i<x;++i)for(register int j=1;j<=n;++j)if(A[i]&bin[j-1]){ans[j]=A[i]>>n;break;}
46         printf("PUZZLE #%d\n",tt);
47         for(register int i=1;i<=n;++i)printf("%d ",ans[i]),(i%6==0)&&printf("\n");
48     }
49     return 0;
50 }
View Code

Finally know how a child playing a game-breaking 100th off

Guess you like

Origin www.cnblogs.com/saigyouji-yuyuko/p/11493589.html