EXTENDED LIGHTS OUT
 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9612 Accepted: 6246

Description

In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each (the actual puzzle has 5 rows of 5 buttons each). Each button has a light. When a button is pressed, that button and each of its (up to four) neighbors above, below, right and left, has the state of its light reversed. (If on, the light is turned off; if off, the light is turned on.) Buttons in the corners change the state of 3 buttons; buttons on an edge change the state of 4 buttons and other buttons change the state of 5. For example, if the buttons marked X on the left below were to be pressed,the display would change to the image on the right.

The aim of the game is, starting from any initial set of lights on
in the display, to press buttons to get the display to a state where all
lights are off. When adjacent buttons are pressed, the action of one
button can undo the effect of another. For instance, in the display
below, pressing buttons marked X in the left display results in the
right display.Note that the buttons in row 2 column 3 and row 2 column 5
both change the state of the button in row 2 column 4,so that, in the
end, its state is unchanged.

Note:

1. It does not matter what order the buttons are pressed.

2. If a button is pressed a second time, it exactly cancels the
effect of the first press, so no button ever need be pressed more than
once.

3. As illustrated in the second diagram, all the lights in the first
row may be turned off, by pressing the corresponding buttons in the
second row. By repeating this process in each row, all the lights in the
first

four rows may be turned out. Similarly, by pressing buttons in
columns 2, 3 ?, all lights in the first 5 columns may be turned off.

Write a program to solve the puzzle.

Input

The
first line of the input is a positive integer n which is the number of
puzzles that follow. Each puzzle will be five lines, each of which has
six 0 or 1 separated by one or more spaces. A 0 indicates that the light
is off, while a 1 indicates that the light is on initially.

Output

For
each puzzle, the output consists of a line with the string: "PUZZLE
#m", where m is the index of the puzzle in the input file. Following
that line, is a puzzle-like display (in the same format as the input) .
In this case, 1's indicate buttons that must be pressed to solve the
puzzle, while 0 indicate buttons, which are not pressed. There should be
exactly one space between each 0 or 1 in the output puzzle-like
display.

Sample Input

```2
0 1 1 0 1 0
1 0 0 1 1 1
0 0 1 0 0 1
1 0 0 1 0 1
0 1 1 1 0 0
0 0 1 0 1 0
1 0 1 0 1 1
0 0 1 0 1 1
1 0 1 1 0 0
0 1 0 1 0 0```

Sample Output

```PUZZLE #1
1 0 1 0 0 1
1 1 0 1 0 1
0 0 1 0 1 1
1 0 0 1 0 0
0 1 0 0 0 0
PUZZLE #2
1 0 0 1 1 1
1 1 0 0 0 0
0 0 0 1 0 0
1 1 0 1 0 1
1 0 1 1 0 1```

Source

Greater New York 2002

.....

30个变量30个方程组

``` #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int MAX=;
int a[MAX][MAX]; //增广矩阵
int x[MAX];  //解集
int equ,var;  //行数和列数
void init()
{
equ=;var=;
memset(a,,sizeof(a));
for(int i=;i<;i++)      //t点和上下左右都改变
for(int j=;j<;j++)
{
int t=*i+j;
a[t][t]=;
if(i>) a[*(i-)+j][t]=;
if(i<) a[*(i+)+j][t]=;
if(j>) a[t-][t]=;
if(j<) a[t+][t]=;
}
}
void gaos()
{
int maxr;
for(int k=,col=;k<equ&&col<var;k++,col++)
{
maxr=k;                      /****变为行阶梯形矩阵***/
for(int i=k+;i<equ;i++)
if(abs(a[i][col])>abs(a[maxr][col]))
maxr=i;
if(maxr!=k)
{
for(int i=col;i<var+;i++)
swap(a[maxr][i],a[k][i]);
}
if(a[k][col]==)  //第k行后的第col列全部是0了，换下一列
{
k--;
continue;
}
for(int i=k+;i<equ;i++)   //第k行减去第i行的值赋给第i行，变为行阶梯型矩阵，由于都是01型矩阵，不用找lcm直接减就行
{
if(a[i][col]!=)
{
for(int j=col;j<var+;j++)
a[i][j]^=a[k][j];
}
}
for(int i=var-;i>=;i--)   //算出解集
{
x[i]=a[i][var];
for(int j=i+;j<var;j++) //该行第var列是1说明该行有且只有一个x取1，若为0说明没有取1的x.
x[i]^=(a[i][j]&x[j]);
}
}
}
int main()
{
int t,ca=;
scanf("%d",&t);
while(t--)
{
ca++;
init();
for(int i=;i<;i++)
scanf("%d",&a[i][]);
gaos();
printf("PUZZLE #%d",ca);
for(int i=;i<;i++)
{
if(i%==) printf("\n%d",x[i]);
else printf(" %d",x[i]);
}
printf("\n");
}
return ;
}```

## *POJ 1222 高斯消元的更多相关文章

1. POJ 1222 POJ 1830 POJ 1681 POJ 1753 POJ 3185 高斯消元求解一类开关问题

http://poj.org/problem?id=1222 http://poj.org/problem?id=1830 http://poj.org/problem?id=1681 http:// ...

2. POJ SETI 高斯消元 + 费马小定理

http://poj.org/problem?id=2065 题目是要求 如果str[i] = '*'那就是等于0 求这n条方程在%p下的解. 我看了网上的题解说是高斯消元 + 扩展欧几里德. 然后我 ...

3. POJ 2065 高斯消元求解问题

题目大意: f[k] = ∑a[i]*k^i % p 每一个f[k]的值就是字符串上第 k 个元素映射的值,*代表f[k] = 0 , 字母代表f[k] = str[i]-'a'+1 把每一个k^i求 ...

4. poj 2065 高斯消元（取模的方程组）

SETI Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1735   Accepted: 1085 Description ...

5. POJ 1830 高斯消元

开关问题   Description 有N个相同的开关,每个开关都与某些开关有着联系,每当你打开或者关闭某个开关的时候,其他的与此开关相关联的开关也会相应地发生变化,即这些相联系的开关的状态如果原来为 ...

6. POJ 1222 EXTENDED LIGHTS OUT（高斯消元）题解

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

7. POJ 1830 开关问题（高斯消元）题解

思路:乍一看好像和线性代数没什么关系.我们用一个数组B表示第i个位置的灯变了没有,然后假设我用u[i] = 1表示动开关i,mp[i][j] = 1表示动了i之后j也会跟着动,那么第i个开关的最终状态 ...

8. POJ 1222 EXTENDED LIGHTS OUT（高斯消元）

[题目链接] http://poj.org/problem?id=1222 [题目大意] 给出一个6*5的矩阵,由0和1构成,要求将其全部变成0,每个格子和周围的四个格子联动,就是说,如果一个格子变了 ...

9. POJ 1222 EXTENDED LIGHTS OUT（高斯消元解XOR方程组）

http://poj.org/problem?id=1222 题意:现在有5*6的开关,1表示亮,0表示灭,按下一个开关后,它上下左右的灯泡会改变亮灭状态,要怎么按使得灯泡全部处于灭状态,输出方案,1 ...

## 随机推荐

1. 有哪些LabVIEW快捷键让你相见恨晚

前言 任何一门工具,当你使用它到极致的时候,往往都朝着这样子的两个方向发展 1. 具有鼠标操作功能的软件,他的使用的极致就是脱离鼠标,迈向键盘 2. 主要是键盘操作的,他的极致就是脚本自动化,或者说一 ...

2. Azure ARM (3) ARM支持的服务类型

<Windows Azure Platform 系列文章目录> 我们在使用ARM创建资源的时候,首先要确认哪些Azure服务,支持ARM模式. 具体内容,我们可以参考连接:https:// ...

3. 解决html表格中内容超出不强制换行和超出宽度自动隐藏并显示省略号

在表格布局中经常会遇到因为表格内容长短的变化导致布局混乱的情况,这个时候我们可能会有为了布局稳定把单元格宽度写死的情况:但是我们设置了宽度却发现超出了宽度之后会自动变大,用css定义元素的overfl ...

4. 照着别人的demo自己试着做了个放大镜效果

原理: A:放大镜   B:小图片 C:大图片可视区域 D:大图片 鼠标的位置应该在放大镜的中央,所以鼠标位置为:clientX=A.offsetLeft()+B.offsetLeft+1/2*A.o ...

5. shell脚本等的操作

1.命令替换:`` 反向单引号,也称重音符.键盘上和~键在一起的那个键呦,千万不要敲成单引号. A. 使用了``后,shell首先替换输出中``括起来的date命令,然后执行整个输出命令. B.命令替 ...

6. JS-商品图片放大器

7. HDU1069:Monkey and Banana(DP+贪心)

Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T ...

8. div垂直居中(js)

window.onload = function(){ var xx = document.documentElement.clientHeight; // 470为要垂直居中的div的高度 he = ...

9. mysqldiff差异比较

1.安装mysql-utilities[root@localhost soft]# yum install  mysql-utilities.noarch 2.比较数据库zentao和数据库db_ze ...

10. c# WPF RichTextBox 文字颜色

public MainWindow() { InitializeComponent(); Run run = new Run("This is my text"); run.For ...