POJ.1222 EXTENDED LIGHTS OUT(高斯消元 异或方程组)
来源:互联网 发布:charles游戏修改数据 编辑:程序博客网 时间:2024/06/05 19:09
POJ.1222 EXTENDED LIGHTS OUT(高斯消元 异或方程组)
标签(空格分隔): 高斯消元
题意分析
给出t组数据,每组数据为一个
输出一个
典型的开关问题,用高斯消元构造一个
代码总览
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#define nmax 35using namespace std;int a[nmax][nmax];int x[nmax];int hash[nmax][nmax];int Gauss(int equ,int var){ int max_r; int col=0; for(int k = 0;k < equ && col < var;k++,col++){ max_r=k; for(int i=k+1;i<equ;i++){ if(abs(a[i][col])>abs(a[max_r][col])) max_r=i; } if(max_r!=k){ for(int j=k;j<var+1;j++) swap(a[k][j],a[max_r][j]); } if(a[k][col]==0){ k--; continue; } for(int i=k+1;i<equ;i++){ if(a[i][col]!=0){ for(int j=col;j<var+1;j++){ a[i][j]^=a[k][j];; } } } } for(int i = var - 1; i >= 0; i--){ x[i]=a[i][var]; for(int j = i + 1; j < var; j++){ x[i] ^= ( a[i][j] && x[j]); } } return 0;}void init(){ memset(x,0,sizeof x); memset(a,0,sizeof a); for(int i = 0;i<5;++i){ for(int j = 0;j<6;++j){ int t = hash[i][j]; a[t][t] = 1; if(i != 0) a[hash[i-1][j]][t] = 1; if(i != 4) a[hash[i+1][j]][t] = 1; if(j != 0) a[hash[i][j-1]][t] = 1; if(j != 5) a[hash[i][j+1]][t] = 1; } }}int main(){ int t,tot = 0; memset(a,0,sizeof a); memset(x,0,sizeof x); for(int i = 0 ;i<5;++i) for(int j = 0;j<6;++j) hash[i][j] = tot++; scanf("%d",&t); for(int kase = 1;kase<=t;++kase){ init(); for(int i = 0;i<30;++i) scanf("%d",&a[i][30]); Gauss(30,30); printf("PUZZLE #%d\n",kase); for(int i = 0;i<5;++i){ for(int j = 0;j<6;++j){ if(!j) printf("%d",x[hash[i][j]]); else printf(" %d",x[hash[i][j]]); } printf("\n"); } } return 0;}
阅读全文
0 0
- POJ 1222-EXTENDED LIGHTS OUT(高斯消元求解异或方程组)
- POJ 1222|Extended Lights Out|高斯消元|异或方程组
- POJ.1222 EXTENDED LIGHTS OUT(高斯消元 异或方程组)
- Poj 1222 EXTENDED LIGHTS OUT (高斯消元解异或方程组 开关问题)
- poj 1222 EXTENDED LIGHTS OUT (高斯消元解异或方程组 开关问题)
- POJ 1222 EXTENDED LIGHTS OUT 高斯消元解异或方程组
- 【POJ1222】EXTENDED LIGHTS OUT 高斯消元、解异或方程组
- POJ 1222 EXTENDED LIGHTS OUT 高斯消元 异或方程 (水
- poj 1222 EXTENDED LIGHTS OUT 高斯消元 异或方程
- POJ 1222 EXTENDED LIGHTS OUT (异或消元)
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元 异或+求逆版本)
- poj 1222 EXTENDED LIGHTS OUT //高斯消元
- POJ 1222 EXTENDED LIGHTS OUT 枚举 || 高斯消元
- POJ 1222 EXTENDED LIGHTS OUT 高斯消元
- poj 1222 EXTENDED LIGHTS OUT 高斯消元
- poj 1222 EXTENDED LIGHTS OUT高斯消元。
- poj 1222 EXTENDED LIGHTS OUT(高斯消元)
- [高斯消元] poj 1222 EXTENDED LIGHTS OUT
- Flex 布局教程:语法篇
- Flex 布局教程:实例篇
- 内存溢出和内存泄漏的区别
- 用clearfix:after消除(DIV块因内部浮动而高度收缩的问题)
- 多线程同步器AQS
- POJ.1222 EXTENDED LIGHTS OUT(高斯消元 异或方程组)
- 选择子序列
- Spring整合CXF
- 清除浮动的作用
- 在 Linux 系统中安装 MySQL 数据库
- C++面试题(1)
- Convert BST to Greater Tree
- HDU
- MySQL字段的增删查改