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> ...
随机推荐
- Ext.grid.EditorGridPanel保存
用get方法传递编辑的数据会出现乱码,解决get乱码的方法就是encodeURI(param),然后在后台转码: String strJson = new String(request.getPar ...
- idea 远程调试
Idea 远程在线测试 描述:在window下开发,部署到Linux服务器上,往往会遇到在windows下正常运行,在Linux服务器下异常,这是需要本地调试远程代码: 操作步骤: 一.代码已知 保证 ...
- 针对通达OA20170729集团版设计门户管理解决方案的具体实例
随着企业信息化建设的深入,应用系统数量不断增加,应用功能不断丰富,数据信息也在呈几何级数增长,在支撑企业正常工作运转的同时,也衍生出许多新的问题: 通达信科根据自身从业多年的行业实践经验,勇于打破传统 ...
- LVS之DR模式实战及高可用性
author:JevonWei 版权声明:原创作品 LVS-DR实现同网段调度web模式 拓扑环境 网络环境 RS1 RIP 192.168.198.138/24 VIP 192.168.198.10 ...
- 垂直居中小记 line-height table vertical-align:middle
垂直居中分两种情况:1.父元素高度确定的单行文本 2.以及父元素高度确定的多行文本. 1.垂直居中-父元素高度确定的单行文本的竖直居中的方法是通过设置父元素的 height 和 line ...
- (4)ES6解构赋值-字符串篇
字符串的解构赋值 let [a,b,c,d,e] = 'Apple'; console.log(a); //A console.log(b); //p console.log(c); //p cons ...
- 201521123025《java程序设计》第七周学习总结
1. 本周学习总结 2. 书面作业 Q1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 public boolean contains(Object o) { r ...
- 201521123025《JAVA程序设计》第6周学习总结
1. 本章学习总结 2. 书面作业 Q1.clone方法 1.1Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注意什么? 要克隆对象要覆盖clon ...
- [BT5]信息收集1-1 Dnsenum
0.工具介绍 The purpose of Dnsenum is to gather as much information as possible about a domain. The progr ...
- 201521123033《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...