枚举第一行所有可能的的情况

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int map[6][7],maze[6][7],ans[6][7];
int dir[5][2]={0,0,1,0,0,1,0,-1,-1,0};
void press(int i,int j)
{
int x,y;
for(int k=0;k<5;k++)
{
x=i+dir[k][0];
y=j+dir[k][1];
if(x>=1&&x<=5&&y>=1&&y<=6)
maze[x][y]=!maze[x][y];
} }
void example()
{
for(int i=1;i<=64;i++)
{
memset(ans,0,sizeof(ans));
memcpy(maze, map, sizeof(map));
int t=i;
for(int j=6;j>=1;j--)
ans[1][j]=t&1,t>>=1;
for(int j=1;j<=6;j++)
if(ans[1][j])
press(1,j);
for(int row=2;row<=5;row++)
for(int j=1;j<=6;j++)
if(maze[row-1][j])
press(row,j),ans[row][j]=1;
int flag=1;
for(int j=1;j<=6;j++)
if(maze[5][j])
{flag=0;break;}
if(flag)
return ;
}
}
int main ()
{
int t;
scanf("%d",&t);
while(t--)
{
for(int i=1;i<=5;i++)
for(int j=1;j<=6;j++)
cin>>map[i][j];
example();
for(int i=1;i<=5;i++){
for(int j=1;j<=5;j++)
printf("%d ",ans[i][j]);
printf("%d\n",ans[i][6]);
}
printf("\n"); } return 0;
}

2304: Lights Out(枚举)的更多相关文章

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

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

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

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

  3. HDU 4770 Lights Against Dudely (2013杭州赛区1001题,暴力枚举)

    Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

  5. POJ-1222EXTENDED LIGHTS OUT-位运算枚举模板

    传送门:http://poj.org/problem?id=1222 题意:开关灯问题,一幅开关的灯中,给出一种操作,使得灯全关掉,(操作一个开关,相邻的灯也会改变) 思路:利用位运算枚举第一行: # ...

  6. bzoj千题计划187:bzoj1770: [Usaco2009 Nov]lights 燈 (高斯消元解异或方程组+枚举自由元)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1770 a[i][j] 表示i对j有影响 高斯消元解异或方程组 然后dfs枚举自由元确定最优解 #in ...

  7. poj 1222 EXTENDED LIGHTS OUT(位运算+枚举)

    http://poj.org/problem?id=1222 题意:给一个确定的5*6放入矩阵.每一个格子都有一个开关和一盏灯,0表示灯没亮,1表示灯亮着.让你输出一个5*6的矩阵ans[i][j], ...

  8. HDU 4770 Lights Against Dudely

    Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. 【高斯消元】Poj 1222:EXTENDED LIGHTS OUT

    Description In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each ...

随机推荐

  1. robotframework+seleniumlibrary自动化测试:测试环境搭建

    robotframework是由python编写的自动化测试框架,使用robotframework需要安装 python库 python 和 robotframework 的下载地址都可百度到 环境搭 ...

  2. jQuery实现 图片的局部放大效果

    <html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> ...

  3. OpenCV中Mat的列向量归一化

    OpenCV中Mat的列向量归一化 http://blog.csdn.net/shaoxiaohu1/article/details/8287528 OpenCV中Mat的列向量归一化 标签: Ope ...

  4. html标签全称和功能介绍

    html标签全称和功能介绍,里面有些大家不常用的,主要是方便大家查找检索   按字母顺序排列 DTD:指示在哪种 XHTML 1.0 DTD 中允许该标签.S=Strict, T=Transition ...

  5. linux expr命令参数及用法详解

    expr用法 expr命令一般用于整数值,但也可用于字符串.一般格式为: #expr argument operator argument expr也是一个手工命令行计数器. #$expr 10 + ...

  6. css:cdata

    javascript <![CDATA[的web标准使用方法   根据W3C XHTML 1.0的规定:在XHTML中,因为<和&这两个符号有特殊意义(小于号用于标签的开始标记), ...

  7. Oracle record 解锁

    Oracle修改表中记录时出现record is locked by another user的弹出框问题 是因为在操作表中数据时没有commit,导致表被锁. 执行下面两行语句: (1)查看被锁表的 ...

  8. 移植Iperf到android 用来学习linux移植到安卓的例子

    Iperf移植记录 1.生成arm编译需要的头文件config.h ./configure --host=arm如果需要make clean make distclean2.增加Android.mk文 ...

  9. 一个不错的PHP文件页面缓存类

    在php中缓存分类数据库缓存,文件缓存和内存缓存,下面我来给各位同学详细介绍PHP文件缓存类实现代码,有需要了解的朋友可参考. 页面缓存类 <?php    /*    * 缓存类    cac ...

  10. CodeIgniter 如何去掉 Index.php

    步骤; 1.打开你的WEB服务器的httpd.conf文件. 2.找到LoadModule rewrite_module modules/mod_rewrite.so这行,把该行前的#去掉.保存该文件 ...