熄灯问题 Lights Out Puzzle

关灯游戏 Lights out (三)(线性代数+高斯消元,搜索全部解) 关灯游戏和线性代数联系紧密,对于一个 的灯阵,用线性方程组+高斯消元法求解,时间复杂度为O(m×n)^3。相对于首行枚举算法复杂度O(2^n) ,线代算法的时间复杂度低很多。用线性代数求解关灯游戏是个很不错的选择。         本文用最通俗的语言介绍线代求解关灯游戏原理。由于解释通俗化,细节之处难以严谨表述,说得不好的地方,请大神轻拍。 线性方程组求解关灯游戏的原理 问题: 阅读详情

From : http://mathworld.wolfram.com/LightsOutPuzzle.html

 

转化为高斯消元法,POJ 1222

 

---

 

 

Lights Out Puzzle

DOWNLOAD Mathematica Notebook

LightsOutSwitch

A one-person game played on a rectangular lattice of lamps which can be turned on and off. A move consists of flipping a "switch" inside one of the squares, thereby toggling the on/off state of this and all four vertically and horizontally adjacent squares. Starting from a randomly chosen light pattern, the aim is to turn all the lamps off. The problem of determining if it is possible to start from set of all lights being on to all lights being off is known as the "all-ones problem." As shown by Sutner (1989), this is always possible for a square lattice (Rangel-Mondragon).

This can be translated into the following algebraic problem.

1. Each lamp configuration can be viewed as a matrix L with entries in Z_2 (i.e., a binary matrix ), where each 1 represents a burning light and 0 represents a light turned off. For example, for the 3×3 case,

 L=[0 1 0; 1 1 0; 0 1 1]
(1)

2. The action of the switch placed at (i,j) can be interpreted as the matrix addition L+A_(ij) , where A_(ij) is the matrix in which the only entries equal to 1 are those placed at (i,j) and in the adjacent positions; there are essentially three different types of matrices A_(ij) , depending on whether (i,j) is a corner entry,

 A_(11)=[1 1 0; 1 0 0; 0 0 0]
(2)

a side entry,

 A_(12)=[1 1 1; 0 1 0; 0 0 0]
(3)

or a middle entry,

 A_(22)=[0 1 0; 1 1 1; 0 1 0]
(4)

3. Since matrix addition is commutative, it follows that the order in which the moves are performed is irrelevant.

4. Every winning combination of moves can be expressed mathematically in the form:

 L+sum_(i,j)x_(ij)A_(ij)=0.
(5)

Here, 0 denotes the zero matrix , which corresponds to the situation where all lights are turned off, and each coefficient x_(ij) represents the number of times that switch (i,j) has to be pressed. Because we are solving the equations (mod 2), they can therefore be written in the equivalent form

 sum_(i,j)x_(ij)A_(ij)=L.
(6)

Furthermore, it suffices to consider 0 and 1 as the only possible values for x_(ij) . Hence, the above equality is in fact a system of linear equations in the indeterminates x_(ij) over the field Z_2 .

LightsOut3By3

For example, the system corresponding to the initial (left) light pattern above can be written as

 [1 1 0 1 0 0 0 0 0; 1 1 1 0 1 0 0 0 0; 0 1 1 0 0 1 0 0 0; 1 0 0 1 1 0 1 0 0; 0 1 0 1 1 1 0 1 0; 0 0 1 0 1 1 0 0 1; 0 0 0 1 0 0 1 1 0; 0 0 0 0 1 0 1 1 1; 0 0 0 0 0 1 0 1 1][x_(11); x_(12); x_(13); x_(21); x_(22); x_(23); x_(31); x_(32); x_(33)]=[0; 1; 0; 1; 1; 0; 0; 1; 1].
(7)

It has exactly one solution: ((1,1,1) , (0,0,0) , (0,0,1) ), which means that the game is solved by pressing the switches (1,1) , (1,2) , (1,3) , and (3,3) (corresponding to the red dots in the figure above). Since the matrix of the above system of equations has maximal rank (it is a 9×9 matrix with nonzero determinant), the game on a 3×3 -lattice is always solvable.

LightsOut3By2Solvable

In general, the solvable patterns of the m×n lattice are those which are obtained from the no-light pattern by pushing some switches. In the language of linear algebra, they are the m×n -matrices which are sums of some matrices A_(ij) . For instance, the solvable patterns of the 3×2 -lattice are illustrated above. All other rectangles of size 4×3 or less are solvable for every possible starting pattern.

LightsOut3By2Solutions

Multiple solutions are sometimes possible. For example, going from lights all on to all off in the 3×2 case, there are four possible solutions to the all-lights pattern, illustrated above.

LightsOut3By2

Some patterns have no solutions. For example, in the 3×2 pattern shown above, it is impossible to turn off all the lights.

LightsOutSquareSolutions

As shown by Sutner (1989), going from all lights on to all lights off is always possible for any size square lattice. The above illustration shows all possible solutions for n=2 to 7. The numbers of solutions (ignoring rotation and reflection) for n=1 , 2, ... are 1, 1, 1, 16, 4, 1, 1, 1, 256, 1, 64, 1, 1, 16, 1, ... (Sloane's A075462 ), and the corresponding minimal numbers of buttons to be pressed are 1, 4, 5, 4, 15, 28, 33, 40, 25, 44, 55, 72, 105, 56, 117, ... (Sloane's A075464 ). The board sizes with unique solutions (counting boards having equivalent solutions by rotation or reflections as distinct) are therefore 1, 2, 3, 6, 7, 8, 10, 12, 13, 15, 18, 20, ... (Sloane's A076436 ; Cowen and Kennedy 2000).

LightsOutUniqueSquareSolutions

Removing solutions that are equivalent by rotation or reflection gives the distinct solutions illustrated above, of which there are 1, 1, 1, 5, 1, 1, 1, 1, 43, 1, 10, 1, 1, 5, 1, ... (Sloane's A075463 ). The board sizes with unique solutions (counting boards having equivalent solutions by rotation or reflections as equivalent) are therefore 1, 2, 3, 5, 6, 7, 8, 10, 12, 13, 15, 17, 18, ... (Sloane's A076437 ).

This entry contributed by Margherita Barile

REFERENCES:

Caro, Y. "Simple Proofs to Three Parity Theorems." Ars Combin. 42 , 175-180, 1996.

Conlon, M. M.; Falidas, M.; Forde, M. J.; Kennedy, J. W.; McIlwaine, S.; and Stern, J. "Inversion Numbers of Graphs." Graph Th. Notes New York 37 , 42-48, 1999.

Cowen, R. and Kennedy, J. "The Lights Out Puzzle." Math. Educ. Res. 9 , 28-32, 2000. http://library.wolfram.com/infocenter/Articles/1231/ .

Cowen, R.; Hechler, S. H.; Kennedy, J. W.; and Ryba, A. "Inversion and Neighborhood Inversion in Graphs." Graph Th. Notes New York 37 , 37-41, 1999.

Goldwasser, J. and Klostermeyer, W. "Maximization Versions of 'Lights Out' Games in Grids and Graphs." Congr. Numer. 126 , 99-111, 1997.

JavaScript Source. "Lights Out." http://javascript.internet.com/games/lights-out.html .

Millstone Website. "Lights Out." http://www.millstone.demon.co.uk/games/lightsout/start.htm .

Rangel-Mondragon, J. "A Catalog of Cellular Automata." http://library.wolfram.com/infocenter/MathSource/505/ .

Raguet-Schofield, R. "Lights Out Palette Demonstration." http://library.wolfram.com/infocenter/Demos/4817/ .

Sloane, N. J. A. Sequences A075462 , A075463 , A075464 , A076436 , and A076437 in "The On-Line Encyclopedia of Integer Sequences."

Sutner, K. "Linear Cellular Automata and the Garden-of-Eden." Math. Intelligencer 11 , 49-53, 1989.

Whitman College Department of Mathematics. "Lights Out." http://www.whitman.edu/offices_departments/mathematics/lights_out/ .




CITE THIS AS:

Barile, Margherita . "Lights Out Puzzle." From MathWorld --A Wolfram Web Resource, created by Eric W. Weisstein . http://mathworld.wolfram.com/LightsOutPuzzle.html

C++ 熄灯问题poj1222:EXTENDED LIGHTS OUT 1222:EXTENDED LIGHTS OUT 描述 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... 阅读详情

相关推荐

poj1222(枚举)熄灯游戏 EXTENDED LIGHTS OUT

EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11373   Accepted: 7273 Description In an extended version of the game Lights Out, is a pu

. 1万+

关灯游戏 Lights out (一)(极速求解)

关灯游戏(Lights Out)         关灯游戏是Tiger Electronics在1995年发行的一款电子游戏。         关灯游戏规则非常简单,在一个M*N阵列里,有若干盏灯亮着(可以全部都亮着),点击任意一盏灯(不管此灯是亮着还是灭着,都可以点),那么该灯以及与该灯相邻的上、下、左、右共五盏灯都同时会变成与自身相反状态,即亮的变灭,灭的变亮(由于边角的特殊性,点击边

MHL_1208980380的博客 2万+

The-Lights-Out-Puzzle:熄灯难题编码器求解器

由以下人员共同准备的文件: · Daniel Olañeta Fariña · Ángel Álvarez Rey 链接到GitHub项目: : 这种做法是在Java(版本11.0.9)中开发的。 执行说明: 要执行此实践,我们需要预先具有包含编码器条目的“ ex /”目录。 如果已经有了该文件夹,我们将位于“ src /”目录中,一旦进入该目录,我们将执行以下命令: · javac ./com/udc/es/rcra/Encoder.java 编译编码器后,我们可以使用以下命令运行它: · java -cp . com.udc.es.rcra.Encoder "ex/arquivo.txt" 最后,我们可以使用telingo运行文件: · telingo com/udc/es/rcra/LightsOutParallelTogAdyaMinimize.lp "ex/ar

小游戏 Lights Out (关灯) 的求解 —— 异或方程组

Author : EvensgnBlog Link :http://www.cnblogs.com/JoeFan/Article Link :http://www.cnblogs.com/JoeFan/p/4338003.html 游戏介绍 Lights Out (关灯)是一款据说在20世纪90年代就已经被设计出的小游戏,游戏的玩法十分简单。 首先,给定一个 n 行 m 列的矩形方格...

weixin_30443075的博客 764

LightsOutPuzzle

LightsOut拼图

react-lights-out:“ Lights Out”是一个逻辑难题游戏,使用单独的灯光进行游戏,可以点亮或熄灭

react-lights-out:“ Lights Out”是一个逻辑难题游戏,使用单独的灯光进行游戏,可以点亮或熄灭

poj1222

EXTENDED LIGHTS OUT 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

◆◇丶生如夏花。谁来订阅我的悲伤 548

高功率半导体叠阵激光快慢轴准直优化技术解析

本文深入解析了高功率半导体叠阵激光快慢轴准直优化技术。针对其光束发散特性,文章系统阐述了从光源建模、光学仿真到透镜选型与参数匹配的完整工程流程,并强调了光束整形对于提升加工精度与效率的核心作用。通过优化快慢轴准直,可将原始散光转变为能量集中、均匀性好的高质量光束,为后续工业应用奠定基础。

php55的博客 713

POJ1222-EXTENDED LIGHTS OUT 熄灯问题

  一道特别经典的枚举题目,核心思想并非仅仅是单纯的枚举,而是通过枚举局部的可能来确定整体的情况,因为在单纯的枚举中,含有大量的不符合要求的情况。当第一行的开关按法唯一确定时,为了迎合题目要求,之后所有按法都唯一确定,当最后一回合按下后,倒数第二行灯已全灭,只需判断最后一行是否全灭即可。通过枚举出局部的情况而确定全局的情况,这种思想大大减少了枚举的盲目性。 Talk is cheap. Show ...

c46550的博客 300

别再乱点U盘里的.exe了!手把手教你彻底清除那个伪装成Usb Disk的蠕虫病毒

本文详细介绍了如何识别、清除和预防伪装成Usb Disk的蠕虫病毒。从识别感染迹象到安全备份文件,再到深度清理病毒残留和构建防护策略,提供了一套完整的U盘病毒解决方案。特别提醒用户注意U盘病毒的风险,并养成良好的使用习惯。

weixin_30496999的博客 670

小红书图文AI创作:输入主题,一键生成图文(coze工作流教程+获取)

输入主题,工作流一键生成小红书风格图文,30s一条,可批量生成

2301_79384090的博客 2800

台州 OJ 2005 熄灯问题 枚举

描述 In an extended version of the gameLights 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, ...

weixin_30918415的博客 187

Springboot信息泄露以及heapdump的利用

努力是为了不平庸~安全有些时候是枯燥的,这一次,让我们先人一步,趣学渗透!

LiBai'S BLOG 3万+

POJ - 1222. EXTENDED LIGHTS OUT(熄灯问题)(二进制枚举)

POJ1222 - EXTENDED LIGHTS OUT(熄灯问题)(二进制枚举) 题目链接 题目大意 有一个由按钮组成的矩阵,其中每行有6个按钮,共5行。每个按钮的位置上有一盏灯。当按下一个按钮后,该按钮以及周围位置(上边、下边、左边、右边)的灯都会改变一次。即,如果灯原来是点亮的,就会被熄灭;如果灯原来是熄灭的,则会被点亮。在矩阵角上的按钮改变3盏灯的状态;在矩阵边上的按钮改变4盏灯的状态...

zxzxin的博客~ 654

C#上位机实战:手把手搭智慧工业数字孪生系统,从设备建模到实时联动全落地

字段长度(字节)说明起始标识2固定为0xAA55,用于判断数据包开始设备ID4唯一标识设备(比如1001代表电机1)数据类型10=布尔(启停),1=浮点数(转速/温度)数据长度4数据字节数(布尔1字节,浮点数4字节)数据内容N实际数据(按数据长度读取)校验位1前面所有字节的异或校验,防止数据篡改结束标识2固定为0x55AA,用于判断数据包结束。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 968

NEU-DET 冷轧钢缺陷检测:基于 YOLOv8 的目标检测与可视化 UI 实现

冷轧钢的生产过程中,由于设备故障、工艺问题或者人为因素,钢板表面可能会出现多种缺陷,如划痕、裂纹、孔洞等,这些缺陷会严重影响钢材的质量。它比之前的版本(如 YOLOv5、YOLOv4)在速度和精度上都有显著提升,并且对硬件要求较低,适合进行工业界面和嵌入式系统的应用。这些版本相较于更大型的模型(如 YOLOv8x)具有更快的推理速度和较低的资源占用,适合工业生产线中的实时应用。通过将训练好的模型部署到工业生产线摄像头中,我们可以实现实时的缺陷检测,极大地提升生产效率和产品质量。

YOLO 737

lights out游戏C语言,Lights Out - Puzzle Game

Lights Out - Puzzle Game作者:Fegeek70次浏览2019-12-14 01:09:03分享Lights Out is deceptively simple with additive puzzle game play and is based on the classic lights out game that provides hours of exiting en...

weixin_33754535的博客 444

C#操作MySQL从入门到精通(3)——新建数据库、新建表

我们要首先新建一个数据库,并且在数据库中新建一系列的表来管理数据库。

qq_34059233的博客 951

C语言中的熄灯问题extended lights out(枚举)POJ1222//乱用函数返回值会遭报应QAQ

Description http://poj.org/problem?id=1222 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 h

lydia_ke的博客 2198

[特殊字符] PetaLinux Qt 程序(WindRadar)无法自动启动问题解决文档

摘要:本文档解决了PetaLinux 2020.1系统中Qt程序(WindRadar)无法开机自动显示界面的问题。通过分析发现,自动启动时缺少DISPLAY=:0.0环境变量导致Qt找不到显示设备。最终在autostart.sh脚本中添加该变量,并完善了字体加载、驱动加载、显示设备检测等流程,确保程序正常自启显示界面。完整脚本包含路径检测、环境配置和错误处理,经验证各项功能均正常运行。

梁俊星的博客 327

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

poj 1222 EXTENDED LIGHTS OUT - 熄灯问题-详解

一个由按钮组成的矩阵,其中每行有6个按钮,共5行。每个按钮的位置上有一盏灯。当按下一个按钮后,该按钮以及周围位置(上边、下边、左边、右边)的灯都会改变一次。即,如果灯原来是点亮的,就会被熄灭;如果灯原来是熄灭的,则会被点亮。在矩阵角上的按钮改变3盏灯的状态;在矩阵边上的按钮改变4盏灯的状态;其他的按钮改变5盏灯的状态。   所以在5x6的矩阵中,左边矩阵中用X标记的按钮表示被按下,右边的矩阵表示...

Patrick的博客 809

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

POJ 1222 EXTENDED LIGHTS OUT (熄灯问题)

Time Limit:1000MS Memory Limit:10000K Total Submissions:8417 Accepted:5441 Description In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 button...

weixin_33976072的博客 147

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

熄灯问题 //北大郭炜老师代码//大量注释 //EXTENDED LIGHTS OUT

1222:EXTENDED LIGHTS OUT 查看提交统计提示提问 总时间限制: 1000ms 内存限制: 65536kB 描述 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,

AKAPinkman的博客 439

java 熄灯问题_POJ1222 EXTENDED LIGHTS OUT(熄灯问题)

DescriptionIn 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,...

weixin_34453486的博客 305
上一篇: ADSL - Android AVD 不能上网问题
下一篇: Friendly name of ASCII
nomad2
博客等级 码龄21年 163粉丝 420原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值