EXTENDED LIGHTS OUT
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6443   Accepted: 4229

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
 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <set>
using namespace std;
int a[][];
void gauss()
{
int i,j,k;
for(i=; i<; i++)
{
for(k=i; k<; k++)
if(a[k][i])break;
if(k!=i)
for(j=; j<; j++)swap(a[i][j],a[k][j]);
for(j=; j<; j++)
{
if(i!=j&&a[j][i])
for(k=; k<; k++)
a[j][k]^=a[i][k];
}
}
}
int main()
{
int n,i,cas=;
cin>>n;
while(n--)
{
memset(a,,sizeof(a));
for(i=; i<; i++)
scanf("%d",&a[i][]);
for(i=; i<; i++)
{
a[i][i]=;
if(i>=)
a[i][i-]=;
if(i<)
a[i][i+]=;
if(i%)
a[i][i-]=;
if((i+)%)
a[i][i+]=;
}
gauss();
printf("PUZZLE #%d\n",cas++);
for(i=; i<; i++)
{
printf("%d",a[i][]);
if((i+)%==)printf("\n");
else printf(" ");
}
}
}

EXTENDED LIGHTS OUT poj1222 高斯消元法的更多相关文章

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

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

  2. uva 1560 - Extended Lights Out(枚举 | 高斯消元)

    题目链接:uva 1560 - Extended Lights Out 题目大意:给定一个5∗6的矩阵,每一个位置上有一个灯和开关,初始矩阵表示灯的亮暗情况,假设按了这个位置的开关,将会导致周围包含自 ...

  3. POJ 1222 EXTENDED LIGHTS OUT(反转)

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12616   Accepted: 8 ...

  4. POJ 1222 EXTENDED LIGHTS OUT(高斯消元解异或方程组)

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10835   Accepted: 6 ...

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

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

  6. poj1222 EXTENDED LIGHTS OUT

    设输入矩阵为A,输出矩阵为B,目标矩阵为C(零矩阵). 方便起见,矩阵行列下标均从1开始. 考虑A矩阵元素a(i,j),B矩阵中与其相邻的元素 b(i,j),b(i - 1, j),b(i + 1,j ...

  7. [POJ1222]EXTENDED LIGHTS OUT(高斯消元,异或方程组)

    题目链接:http://poj.org/problem?id=1222 题意:开关是四连通的,每按一个就会翻转自己以及附近的四个格(假如有).问需要翻转几个,使他们都变成关. 把每一个灯看作一个未知量 ...

  8. [Gauss]POJ1222 EXTENDED LIGHTS OUT

    题意:给一个5*6的矩阵 1代表该位置的灯亮着, 0代表该位置的灯没亮 按某个位置的开关,可以同时改变 该位置 以及 该位置上方.下方.左方.右方, 共五个位置的灯的开.关(1->0, 0-&g ...

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

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

随机推荐

  1. php工具方法

    备忘常用方法 1.寻找子栏目(权限\菜单列表...) function getSon($list,$pid){ $arr=''; foreach ($list as $k=>$v){ if($v ...

  2. 搭建LAMP及wordpress

    author:JevonWei 版权声明:原创作品 安装软件包 [root@danran ~]# yum -y install httpd mariadb-server mariadb php php ...

  3. 图片懒加载Demo

    相关知识: [js获取元素位置+元素大小]全面总结

  4. Android学习记录:SQLite数据库、res中raw的文件调用

    SQLite数据库是一种轻量级的关系型数据库. 在android中保存数据或调用数据库可以利用SQLite. android中提供了几个类来管理SQLite数据库 SQLiteDatabass类用来对 ...

  5. Httpservlet 获取json对象字符窜

    使用的是google 的json转换jar import com.google.gson.JsonObject;import com.google.gson.JsonParser; import or ...

  6. 利用 VMWare 搭建随机拓扑网络

    这篇文章是计算机网络上机实验课的作业. 实验任务:利用 VMWare 搭建一个由 5 个主机组成的随机拓扑的网络.要求该网络中至少有 2 个子网,两个路由器 .实验的网络拓扑图如下: 网络中有两个路由 ...

  7. 即时作图新工具—ProcessOn【推荐】

    www.processon.com 推荐这个在线作图网站:免费登录,云端存储,面向对象,最重要的是提供了丰富模板! 在线软件的人气会越来越高,这是趋势啊~

  8. 【Beta阶段】第七次scrum meeting

    Coding/OSChina 地址 1. 会议内容 学号 主要负责的方向 昨日任务 昨日任务完成进度 接下去要做 99 PM 配合100完成联网功能 100% 设置个人中心的设计 100 DEV 开始 ...

  9. 团队作业4——第一次项目冲刺(Alpha版本)4.24

    ·本次会议为第三次Scrum Meeting会议~ ·本次会议项目经理召开时间为15:00,在教学楼教室召开,召开时长约30分钟,探讨了昨日任务的进展.遇到的困难以及后续所要开展的工作. 1.站立式会 ...

  10. 201521123094 《Java程序设计》第1周学习总结

    1. 本周学习总结 ① Java根据应用领域分为三大平台:Java SE.Java EE.Java ME.Java SE平台,作为各大平台的基础,它分成JVM/JRE/JDK/Java语言四个主要部分 ...