题意:5*6的格子,你翻一个地方,那么这个地方和上下左右的格子都会翻面,要求把所有为1的格子翻成0,输出一个5*6的矩阵,把要翻的赋值1,不翻的0,每个格子只翻1次

思路:poj 1222 高斯消元详解

代码:

#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define eps 1e-9
typedef long long ll;
const int maxn = 1e4 + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
int a[][], x[], Case = ;
int equ, var;
int free_num,free_x[];
int Gauss(){
int max_r, col, k;
free_num = ;
equ = var = ;
for(k = , col = ; k < equ && col < var; k++, col++){
max_r = k;
for(int i = k + ; i < equ; i++){
if(abs(a[i][col]) > abs(a[max_r][col]))
max_r = i;
}
if(a[max_r][col] == ){
k--;
free_x[free_num++] = col;
continue;
}
if(max_r != k){
for(int j = col; j < var + ; j++){
swap(a[k][j], a[max_r][j]);
}
}
for(int i = k + ; i < equ; i++){
if(a[i][col] != ){
for(int j = col; j < var + ; j++){
a[i][j] ^= a[k][j];
}
}
}
}
for(int i = k; i < equ; i++){
if(a[i][col] != )
return -;
}
if(k < var) return var - k;
for(int i = var - ; i >= ; i--){
x[i] = a[i][var];
for(int j = i + ; j < var; j++){
x[i] ^= (a[i][j] & x[j]);
}
}
return ;
}
int pos(int i, int j){
return i * + j;
}
void solve(){
int u;
memset(a, , sizeof(a));
memset(x, , sizeof(x));
for(int i = ; i < ; i++){
for(int j = ; j < ; j++){
if(i > ) a[pos(i - , j)][pos(i, j)] = ;
if(i < ) a[pos(i + , j)][pos(i, j)] = ;
if(j > ) a[pos(i, j - )][pos(i, j)] = ;
if(j < ) a[pos(i, j + )][pos(i, j)] = ;
a[pos(i, j)][pos(i, j)] = ;
int u;
scanf("%d", &u);
a[pos(i, j)][] = u;
}
}
Gauss();
printf("PUZZLE #%d\n", Case++);
for(int i = ; i < ; i++){
for(int j = ; j < ; j++){
if(j != ) printf(" ");
printf("%d", x[pos(i, j)]);
}
printf("\n");
}
}
int main(){
int T;
scanf("%d", &T);
while(T--){
solve();
}
return ;
}

POJ 1222 EXTENDED LIGHTS OUT(高斯消元)题解的更多相关文章

  1. POJ 1222 EXTENDED LIGHTS OUT (高斯消元)

    题目链接 题意:5*6矩阵中有30个灯,操作一个灯,周围的上下左右四个灯会发生相应变化 即由灭变亮,由亮变灭,如何操作使灯全灭? 题解:这个问题是很经典的高斯消元问题.同一个按钮最多只能被按一次,因为 ...

  2. POJ 1222 EXTENDED LIGHTS OUT [高斯消元XOR]

    题意: $5*6$网格里有一些灯告诉你一开始开关状态,按一盏灯会改变它及其上下左右的状态,问最后全熄灭需要按那些灯,保证有解 经典问题 一盏灯最多会被按一次,并且有很明显的异或性质 一个灯作为一个方程 ...

  3. poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8481   Accepted: 5479 Description In an ...

  4. POJ1222 EXTENDED LIGHTS OUT 高斯消元 XOR方程组

    http://poj.org/problem?id=1222 在学校oj用搜索写了一次,这次写高斯消元,haoi现场裸xor方程消元没写出来,真实zz. #include<iostream> ...

  5. POJ 1222【异或高斯消元|二进制状态枚举】

    题目链接:[http://poj.org/problem?id=1222] 题意:Light Out,给出一个5 * 6的0,1矩阵,0表示灯熄灭,反之为灯亮.输出一种方案,使得所有的等都被熄灭. 题 ...

  6. POJ 1222 熄灯问题【高斯消元】

    <题目链接> 题目大意: 有一个5*6的矩阵,每一位是0或者1. 没翻转一位,它的上下左右的数字也为改变.(0变成1,1变成0).要把矩阵中所有的数都变成0.求最少翻转次数的方案,输出矩阵 ...

  7. [poj1222]EXTENDED LIGHTS OUT(高斯消元)

    题意:每个灯开启会使自身和周围的灯反转,要使全图的灯灭掉,判断灯开的位置. 解题关键:二进制高斯消元模板题. 复杂度:$O({n^3})$ #include<cstdio> #includ ...

  8. EXTENDED LIGHTS OUT (高斯消元)

    In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each (the actual ...

  9. POJ 1681---Painter's Problem(高斯消元)

    POJ   1681---Painter's Problem(高斯消元) Description There is a square wall which is made of n*n small s ...

  10. POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)

    POJ 1222 EXTENDED LIGHTS OUT 今天真是完美的一天,这是我在poj上的100A,留个纪念,马上就要期中考试了,可能后面几周刷题就没这么快了,不管怎样,为下一个200A奋斗, ...

随机推荐

  1. servlet输出请求头

    1.参考 Enumeration headerNames = req.getHeaderNames(); while(headerNames.hasMoreElements()) { String h ...

  2. getParameter和getAttribute区别

    (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter ...

  3. Redis的五种数据结构的内部编码

    type命令实际返回的就是当前键的数据结构类型,它们分别是:string(字符串).hash(哈希). list(列表).set(集合).zset(有序集合),但这些只是Redis对外的数据结构. 实 ...

  4. PHPExcel 基本用法详解

    .header header("Content-Type:application/vnd.ms-excel"); header("Content-Disposition: ...

  5. [vue]vue双向绑定$on $emit sync-模态框

    双向绑定实现($on $emit) 关于父子之间数据更新同步, 如果单向绑定, 子修改了,父却没有修改, 这种一般不符合规范 正常更新数据的套路是: 1. 子通知父更新数据 2. 子自动刷新获取最新数 ...

  6. hdu3339In Action(最短路+01背包)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, whe ...

  7. css中外边距

    1.内部元素设置margin等,父元素高度不能适应 .classA { height: 200px; background-color: cornflowerblue; overflow: hidde ...

  8. Xcode 快捷键及代码格式化

    按住apple键点击类名就可以定位到这个类中查看相关定义(在日后的开发中我们会经常这么来做,毕竟要记住iOS开发中所有的API是不现实的,有些API我们可以通过这种方法来查找) PS:下面都是网上百度 ...

  9. Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class

    转自http://www.anylogic.com/anylogic/help/index.jsp?topic=/com.xj.anylogic.help/html/code/Arrays_Colle ...

  10. 兼容安卓和ios实现一键复制内容到剪切板

    实现代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <m ...