ZOJ 1354 Extended Lights Out

STM32G070xx将Flash页分块方式存储,固定数据块存储,实现一次擦除多次写入 本例程使用STM32G070xx芯片,Flash大小128KB,Flash每页(2048字节)写满后再擦除。操作存储区分为64块,每块32字节,即写满64次擦除一次;标定存储区分为16块,每块128字节,即写满16次擦除一次,每个存储区的块都有各自的头部标记 阅读详情
Extended Lights Out

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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's or 1's 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's 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


灯亮则5(也可能是3或4)个位置上有奇数个开关,否则有偶数个开关。
枚举第一行的开关情况,有了第一行就可以根据灯的亮与暗依次推出第二行第三行一直到第五行的开关情况
再根据推出的第五行的开关情况所对应的灯的亮暗与给出的第五行的灯泡情况进行比较从而判断出所求矩阵

代码如下:

#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

int a[8][8], b[8][8];
int counted(int i, int j)
{
    int cnt = 0;
    if(b[i][j])
        cnt++;
    if(b[i-1][j])
        cnt++;
    if(b[i][j+1])
        cnt++;
    if(b[i][j-1])
        cnt++;
    return cnt;
}
int DFS()
{
    for(int i = 1; i <= 4; i++)
        for(int j = 1; j <= 6; j++)
        {
            int cnt = counted(i, j);
            if(cnt % 2 == a[i][j])  // 如果周围开关数目与现有位置上的开关数的奇偶性相同,
                b[i+1][j] = 0;      // 则下一行相应位置为0(即:没有开关),否则为1
            else
                b[i+1][j] = 1;
        }
    for(int i = 1; i <= 6; i++)     
    {
        int cnt = counted(5, i);  // 如果推出的第五行的开关数所对应的灯的亮暗与给出的第五行的灯泡情况不相同,则返回0继续判断下种情况
        if(cnt % 2 != a[5][i])
            return 0;
    }
    return 1;
}
void light()  //枚举第一行的所有情况(2的6次方种情况)
{
    for(int i = 0; i < 2; i++)
    {
        b[1][1] = i;
        for(int i1 = 0; i1 < 2; i1++)
        {
            b[1][2] = i1;
            for(int i2 = 0; i2 < 2; i2++)
            {
                b[1][3] = i2;
                for(int i3 = 0; i3 < 2; i3++)
                {
                    b[1][4] = i3;
                    for(int i4 = 0; i4 < 2; i4++)
                    {
                        b[1][5] = i4;
                        for(int i5 = 0; i5 < 2; i5++)
                        {
                            b[1][6] = i5;
                            int flag = DFS();
                            if(flag)  // 如果找到则跳出
                                return ;
                        }
                    }
                }
            }
        }
    }
    puts("8");
}
int main()
{
#ifdef test
    freopen("in.txt", "r", stdin);
#endif
    int t, num = 0;
    scanf("%d", &t);
    while(t--)
    {
        for(int i = 1; i <= 5; i++)
            for(int j = 1; j <= 6; j++)
                scanf("%d", &a[i][j]);
        for(int i = 0; i < 8; i++)
            for(int j = 0; j < 8; j++)
                b[i][j] = 0;
        printf("PUZZLE #%d\n",++num);
        light();
        for(int i = 1; i <= 5; i++)
            for(int j = 1; j <= 6; j++)
                printf("%d%c", b[i][j], j != 6 ?' ':'\n');
    }
    return 0;
}


17、Nimble 包开发与并行编程指南 本文介绍了Nimble包的开发与版本管理流程,涵盖语义化版本控制规范及发布步骤;深入探讨了Nim中的并行编程基础,包括并发与并行的区别、threads模块与threadpool模块的使用方法及其差异;分析了线程执行的不确定性、线程池的优势,并提供了线程同步和资源管理的实践示例,帮助开发者高效构建稳定、高性能的Nim应用程序。 阅读详情

相关推荐

变邻域搜索(VNS)原理梳理和应用细节-附求解VRPTW问题C++代码

文章目录1、简介-introduction2、VNS的基本机制2.1 变邻域下降方法-Variable Neighborhood Descent2.2基本变邻域搜索方法-Basic Variable Neighborhood Search2.3 终止准则3、VNS的拓展和混杂算法3.1 VNS的拓展3.2 变邻域分解搜索-Variable Neighborhood Decomposition Search3.3 偏变邻域搜索-Skewed VNS3.4 并行变邻域搜索-Parallel VNS4、VNS和其

dragon Fly的博客 6826

ZOJ 1354 Extended Lights Out(枚举)

枚举第一行的64种可能,然后对于除第一行的每一个i,j值,若[i-1,j]亮着灯就要把[i,j]开关开起来关掉[i-1,j]的灯 #include #include #include using namespace std; bool maze[5][6],ans[5][6],temp[5][6]; int cnt[5][6]; int di[]={0,-1,1,0,0},dj[]={0

蚂蚁大战大象 580

SQL注入:联合查询的三个绕过技巧

在SQL注入中,可以利用科学计数法来绕过对输入的限制。例如,可以使用科学计数法来绕过对字符串长度的限制,通过将字符串拆分成多个部分并使用科学计数法来表示。此外,还可以利用数据库的特定特性或语法来替代原始的查询语句,从而执行联合查询或其他恶意操作。另外,还可以尝试利用无列名注入的技巧,通过在原始查询中使用通配符或其他方式来绕过对列名的限制,从而执行恶意操作。

qq_68163788的博客 3792

ZOJ 1354(枚举,模拟)

题意:有一个5*6的矩阵分别代表有这么多灯,有一些灯开着,有一些关着的。现在给出所有灯的初状态,让你输出使所有灯都关闭的开关按法。 思路:1.直接枚举所有开关的情况,即枚举2^30种情况,显然这是不能接受的。       2.转化一下思维,假设第一行灯的情况已知,那么我们只需要按第二行的开关就能将第一行灯全部灭掉(按第一行亮着的灯所对应第二行的开关即可)。同理可得,第三行开

On the way 588

JDK8升级JDK17过程中遇到的那些坑

JDK8虽然非常好,但是JDK版本已经发布到JDK20了,且JDK8后的版本升级了很多新的特性,如模块化、ZGC以及虚拟线程、结构性并发等,也是非常有吸引力的,所以决定将基于JDK8的项目升级到最近的LTS版本JDK17。

BASK2312的博客 6685

Android13系统设置第三方app为设备所有者

DevicePolicyManagerService.java文件所在目录是frameworks/base,记得将包类名换成自己app的。2. 将拷贝到系统分区下的两个xml文件继续通过init.rc服务拷贝到data/system/目录下并修改权限。1. 拷贝设备所有者和设备管理器两个对应的xml文件到系统分区。

wzh048503的博客 2503

POJ1222 UVA1560 LA2561 ZOJ1354 EXTENDED LIGHTS OUT【暴力】

EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16345 Accepted: 9867 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). Eac

海岛Blog 515

从零到一:基于Rocky Linux 9的Kubernetes高可用集群部署实战

本文提供了一份基于Rocky Linux 9操作系统,从零开始部署Kubernetes高可用集群的完整实战指南。详细讲解了包括系统初始化、容器运行时配置、使用kubeadm工具进行集群初始化、节点加入以及Calico网络插件安装在内的核心步骤,并针对国内网络环境提供了镜像加速等优化方案,旨在帮助读者构建一个稳定可靠的生产级K8s环境。

weixin_29197835的博客 137

Extended Lights Out--ZOJ 1354

1、解题思路:贪心、枚举、位运算。 2、注意事项: 位运算:注意^ 、^、<<; 递归:注意剪枝; 3、实现方法: 1 #include <iostream> 2 using namespace std; 3 #define ROW 5 4 #define COL 6 5 6 bool isOK; 7 ...

weixin_34378922的博客 98

旋转因子量化仿真

在单bit接收机中,通过量化FFT核函数来简化计算,将复数坐标中旋转因子单位圆上的点近似到正方形四个边上,就能够用累加实现复数乘法,从而避免使用DSP乘法器。通过仿真查看不同阶的核函数简化效果。

CyberInversion的博客 3103

S32K344 Bootloader实战:一个按键实现从Boot到App的无缝跳转(附完整代码)

本文详细介绍了基于NXP S32K344微控制器的Bootloader开发实战,重点解析如何通过一个硬件按键实现从Boot到App的可靠跳转。内容涵盖内存分区规划、中断向量表重映射、外设初始状态管理等核心要素,并提供了完整的代码示例和调试技巧,适用于汽车电子和工业控制等高可靠性应用场景。

weixin_29192365的博客 307

poj1222||zoj 1354 Extended Lights Out(枚举)

好恨啊,枚举题都不行了。看了报告才会做的。不过这也算是一个类型题,且yy一番。 题目是说有个6*5的0-1状态,开关可以控制其边上的4个灯。要求灯全灭的开关状态。 所有的状态有2^30个全部枚举基本上是不可能的…>_ 有个好方法是:只要第一行有个确定的结果,就可以推出剩下的各行。 问题1:怎么确定第一行:这里就体现了何为枚举….额,6层循环举出了第一行的状态。 问题2:怎么推出2-5行的

uiiの技术随笔 1138

【C++】开源:ncurses终端TUI文本界面库

ncurses配置使用(TUI)

DevFrank的博客 3167

「ZOJ 1354」Extended Lights Out「高斯消元」

题意:给定一个\(5\times 6\)的棋盘的\(01\)状态,每次操作可以使它自己和周围四个格子状态取反,求如何操作,输出一个\(01\)矩阵 题解:这题可以通过枚举第一行的状态然后剩下递推来做,但是这里还是写一种好理解的高斯消元解异或方程组的方法。 对于每个格子列一个方程,未知数就是要求的答案矩阵,系数的话把它周围的设为1,其他设为0。然后右边的常数项为它本来的状态。然后就高斯消元嘛。 我用...

weixin_30685029的博客 123

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

ZOJ 1354 Extended Lights Out——高斯消元法解XOR方程

原题地址 Extended Lights Out Time Limit: 2 Seconds      Memory Limit: 65536 KB In an extended version of the game Lights Out , is a puzzle with 5 rows of 6 buttons each (the actual puzzle has 5

西柚酱的学习blog 619

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

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

poj 1222 & zoj 1354 EXTENDED LIGHTS OUT (枚举)

http://poj.org/problem?id=1222 和poj 1753类似,1753是求全0或全1的步数,这题是求全0的解决方案。 当时是拿1753的代码改的,枚举步数,最多30步,这样的话状态总量就是2^30。。。 枚举第一行状态,共2^6,第一行确定了便可确定其余行,最后看末行是否全为0即可。code:#include<cstdio>#include<cstring...

weixin_34219944的博客 122

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

UVa 140 - Bandwidth

全排列,统计记录每个排列中“带宽”最大的值,最后输出所有最大值中最小的那个。 代码如下: #include #include #include #include #include #include using namespace std; int cct, ahl[27], map[27][27]; int save[9], node[9]; char a[500]; int

GooMaple 2202

UVa 11624 - Fire!

bfs,稍复杂的bfs,将火和人的位置分别bfs(先火再人),直到人到达边界或是被火围住无路可走时结束。 代码如下: #include #include const int MAXN = 1001; struct point { int x, y, mem_step; bool bool_fire;// 区分是否是‘火’ } que[MAXN*MAXN]; int r,

GooMaple 2002

UVa 10001 - Garden of Eden

这个题难点在理解题意,读了n遍都没有读懂,最后看的结题报告上的解释才明白它的意思。 题意:一共有256种自动机的编译形式,给你其中一种,你可以相应转换为对应的二进制数字串(即为表格中的一个New State),再根据这个标准编译串(New state)将给出的串逆转换,如果能逆转换成一个符合要求的新串则说明存在串可以转换为给出的串,则输出“REACHABLE”,否则不存在,输出“GARDEN O

GooMaple 1845

UVa 208 - Firetruck

总体思路很简单,回溯,但直接用矩阵回溯会TLE。因为可能在1与目标点之间不存在通路(即:1 与 目标点分别存在于两个隔绝的联通图中),这样如果直接从1开始往下回溯,会无谓检查到许多无用的点浪费时间,我们可以先将所有与目标点联通的点存于一个数组中,仅在这个数组中查找,就省去很多无谓的查找时间。 代码如下: #include #include #include #include #in

GooMaple 1761

UVa 167 - The Sultan's Successors

经典“八皇后问题”,把所有情况全部遍历一遍,统计最大值即可。 代码如下: #include #include #include #include #include using namespace std; int a[9][9], vis[3][20], save[9], n, tot; void search(int cur) { int i; if(cur

GooMaple 1705

2010年山东省第一届ACM大学生程序设计竞赛——Balloons

DFS水题。打选拔赛时的一个题,当时还没有开数据结构,所以没做上,今天看了看真是不难,AC掉了,也算是正式开图题的一个吧~~~ 代码如下: #include #include #include #include #include #include using namespace std; char a[100+2][100+2]; int flag_s[100+2][100+2],

GooMaple 1617

UVa 10012 - How Big Is It?

以为很简单,十分钟敲了一个全排列回溯,结果WA了。想了半天,才想到可能存在两个半径很大的圆相切,中间夹着很多小的圆(这样单纯的全排列只判断相邻两圆的话就可能出现圆圆相交的情况),这样就需要加一个圆心坐标和一个原点记录位置来做特判,令当前放置的圆与前面所有的圆相切求出最大的据原点的距离(这样就可以保证排除圆圆相交的情况),再加上前面的距离即为放置这个新的圆的位置坐标。 代码如下: #incl

GooMaple 1525

UVa 657 - The die is cast

题还是蛮简单的,不过因为将main()函数的reture 0写到了while里,导致WA了好几遍,当时老纠结了,怎么看怎么对,但就是WA,哎,太粗心了~~~ 两次DFS,对骰子进行一次DFS,再对骰子里面的数字进行一次DFS ~ 代码如下: #include #include #include #include #include #include using name

GooMaple 1475

UVa 10344 - 23 out of 5

开始用的回溯TLE了,后来改用全排列+DFS  AC。 代码如下: (0.728s): #include #include #include #include #include #include using namespace std; int a[5], flag; void solve(int cur, int sum) { if(cur == 5) {

GooMaple 1449

UVa 188 - Perfect Hash

按照题目说的去模拟就可以,唯一值得注意的是,两个单词之间可能不止一个空格,因为这个RE了好几次。 代码如下: #include #include #include #include #include #include using namespace std; int main() { #ifdef test freopen("sample.txt", "r", st

GooMaple 1425
上一篇: ZOJ 1877 Bridge
下一篇: URAL 1102 Strange Dialog
GooMaple
博客等级 码龄14年 79粉丝 197原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值