EXTENDED LIGHTS OUT poj1222 高斯消元法
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6443 | Accepted: 4229 |
Description

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
Output
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 高斯消元法的更多相关文章
- POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)
POJ 1222 EXTENDED LIGHTS OUT 今天真是完美的一天,这是我在poj上的100A,留个纪念,马上就要期中考试了,可能后面几周刷题就没这么快了,不管怎样,为下一个200A奋斗, ...
- uva 1560 - Extended Lights Out(枚举 | 高斯消元)
题目链接:uva 1560 - Extended Lights Out 题目大意:给定一个5∗6的矩阵,每一个位置上有一个灯和开关,初始矩阵表示灯的亮暗情况,假设按了这个位置的开关,将会导致周围包含自 ...
- POJ 1222 EXTENDED LIGHTS OUT(反转)
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12616 Accepted: 8 ...
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元解异或方程组)
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10835 Accepted: 6 ...
- poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8481 Accepted: 5479 Description In an ...
- poj1222 EXTENDED LIGHTS OUT
设输入矩阵为A,输出矩阵为B,目标矩阵为C(零矩阵). 方便起见,矩阵行列下标均从1开始. 考虑A矩阵元素a(i,j),B矩阵中与其相邻的元素 b(i,j),b(i - 1, j),b(i + 1,j ...
- [POJ1222]EXTENDED LIGHTS OUT(高斯消元,异或方程组)
题目链接:http://poj.org/problem?id=1222 题意:开关是四连通的,每按一个就会翻转自己以及附近的四个格(假如有).问需要翻转几个,使他们都变成关. 把每一个灯看作一个未知量 ...
- [Gauss]POJ1222 EXTENDED LIGHTS OUT
题意:给一个5*6的矩阵 1代表该位置的灯亮着, 0代表该位置的灯没亮 按某个位置的开关,可以同时改变 该位置 以及 该位置上方.下方.左方.右方, 共五个位置的灯的开.关(1->0, 0-&g ...
- POJ1222 EXTENDED LIGHTS OUT 高斯消元 XOR方程组
http://poj.org/problem?id=1222 在学校oj用搜索写了一次,这次写高斯消元,haoi现场裸xor方程消元没写出来,真实zz. #include<iostream> ...
随机推荐
- fileZilla 设置 记录一笔 以防忘记
- [js高手之路]深入浅出webpack教程系列8-(postcss-loader,autoprefixer,html-loader,less-loader,ejs-loader)用法
我们接着上文,那么在上篇文章的最后,写到了css-loader的用法,如果你用心发现,就能看到我在style.css样式文件中写了一个这样的样式: div { transition: all ease ...
- python爬虫scrapy框架——人工识别知乎登录知乎倒立文字验证码和数字英文验证码
目前知乎使用了点击图中倒立文字的验证码: 用户需要点击图中倒立的文字才能登录. 这个给爬虫带来了一定难度,但并非无法解决,经过一天的耐心查询,终于可以人工识别验证码并达到登录成功状态,下文将和大家一一 ...
- 第3阶段——内核启动分析之创建si工程和分析stext启动内核函数(4)
目标: (1)创建Source Insight 工程,方便后面分析如何启动内核的 (2)分析uboot传递参数,链接脚本如何进入stext的 (3) 分析stext函数如何启动内核: (3.1) ...
- 汇编指令-bic(位清除)、orr(位或)(3)
1. bic (Bit Clear)位清除指令bic指令的格式为:bic{条件}{S} Rd,Rn,operand bic指令将Rn 的值与操作数operand2 的反码按位逻辑"与&q ...
- sqlserver与mysql中vachar(n)中遇到的坑
前两天在做将mysql的数据表导入到sqlserver当中. 本人比较愚笨,操作方法 是先将mysql的数据表到处为insert脚本,再在sqlserver中执行sql脚本 在网上看了一下那些方法 , ...
- 嵌套ajax 页面卡死的问题
问题:要一个AJAX中的回调函数中又进行了一个AJAX调用,并且这个AJAX是在一个循环调用的,不论设置async属性是true和false页面卡死. 解决方法:async属性都设为true,不用循环 ...
- FFmpeg 常用命令收集
FFmpeg 常用命令 合并视频 ffmpeg -i "KTDS-820A_FHD.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts i ...
- 英语app分析
Andorid 版本 第一部分 调研, 评测 搜索了一下必应跑出来的是微软必应,在印象中微软的产品都是很可靠地.安装之后对它的 排版字体图片等不是很喜欢,感觉有道词典会更亲切一点. 必应 ...
- 结对编程-四则运算生成程序-GUI界面
201421123118 张中结 201421123098 胡丹丹 a.需求分析 这个程序做成GUI(可以是Windows PC 上的,也可以是Mac.Linux,web,手机上的),成为一个有基本功 ...