zoukankan      html  css  js  c++  java
  • poj 1222 EXTENDED LIGHTS OUT

    题目链接

    poj 1222 EXTENDED LIGHTS OUT

    题解

    高斯消元解异或方程
    一盏灯最多会被按一次
    一个灯作为一个式子的一个变量
    两盏灯相互影响系数设为1,补影响设为0
    常数项代表最后需不需要这盏灯改变状态
    guass消元解这个异或方程组就行了

    代码

    #include<cstdio>
    #include<bitset>
    #include<algorithm>
    using std::bitset;
    const int maxn = 37;
    bitset<maxn> a[maxn];
    inline int read() {
    	int x = 0,f = 1;
    	char c = getchar();
    	while(c < '0'||c > '9') {if(c == '-') f = -1;c=getchar();}
    	while(c <='9'&&c >= '0') x=x*10+c-'0',c=getchar();
    	return x * f;
    }
    void Guass() {
    	int now = 1;
    	for(int i = 1;i <= 30;++ i) {
    		int j = now;
    		while(j <= 30 && !a[i][j]) j++;
    		if(now != j) swap(a[now],a[j]);
    		for(int k = 1;k <= 30;++ k) 
    			if(k != now && a[k][i]) a[k]^=a[now];
    		now++;
    	}
    }
    int main() {
    	int T = read();
    	for(int t = 1;t <= T; ++t) {
    		for(int i = 1;i <= 5; ++ i) 
    			for(int j = 1;j <= 6;++ j) {
    				int id = (i - 1) * 6 + j;
    				a[id][id]=1;
    				if(i!=1) a[id][id - 6] = 1;
    				if(i!=5) a[id][id + 6] = 1;
    				if(j!=1) a[id][id - 1] = 1;
    				if(j!=6) a[id][id + 1] = 1;
    				a[id][31] = read();
    			}
    		Guass();
    		printf("PUZZLE #%d
    ",t);
    		for(int i = 1;i <= 5;++ i) { 
    			for(int j = 1;j <= 6;++ j) 
    				printf("%d ",a[(i-1)*6+j][31] ? 1 : 0);	
    			puts("");
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    centos7 mysql 数据库备份与还原
    Centos 7 搭建wordpress
    Centos 7 安装 mysql5.7
    linux 搭建php网站许愿墙
    GNOME桌面的安装
    cetnos 7 ntp服务的安装与配置
    Tornado初探
    Mysql报错 Cannot load from mysql.proc
    zabbix install
    PYPY_GC
  • 原文地址:https://www.cnblogs.com/sssy/p/8684443.html
Copyright © 2011-2022 走看看