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

#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. HDU 5805 NanoApe Loves Sequence

    处理出每个位置左边的最大值和右边的最大值.然后就可以o(1)计算去掉某位置的最大值了. #pragma comment(linker, "/STACK:1024000000,10240000 ...

  2. VBS 读取文本文件特殊字符前如逗号的值并赋值给变量

    我使用的仿真终端SecureCRT需要使用一个脚本,支持VBS的.我需要实现如下功能: 首先文本文件在:D:\100.txt文本文件的内容为:9 0,randy,9 1,jeff,9 2,sameul ...

  3. hdu_4507_吉哥系列故事——恨7不成妻(鬼畜数位DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4507 题意:中文,不解释,注意的是求的是合法数字的平方和,即(a+b+c+……)^2 题解:数位DP, ...

  4. css3 media媒体查询器用法总结 兼容ie8以下的方法

    总结一下响应式设计的核心CSS技术Media(媒体查询器)的用法. http://www.360doc.com/content/14/0704/06/10734150_391862769.shtml ...

  5. LVS负载均衡的三种模式和八种算法总结

    三种LVS负载均衡模式 调度器的实现技术中,IP负载均衡技术是效率最高的,IP虚拟服务器软件(IPVS)是在linux内核中实现的。 LVS负载均衡模式---1.NAT模式 NAT用法本来是因为网络I ...

  6. 克隆虚拟机系统整个文件快照,然后另起建立该系统,产生的IP地址冲突解决办法

    进入克隆后的文件系统 cd /etc/sysconfig/network-scripts/ cp ifcfg-eth0  ifcfg-eth1 vim ifcfg-eth1   #修改其中的文件内容 ...

  7. tablehost

    返回键的拦截 @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEven ...

  8. 滚动视图UIScrollView

    int i; @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super ...

  9. 使用VS2013编译webkit

    环境: win7_x64.VS2013 开始: 一.下载webkit 从网站"https://github.com/WebKit/webkit"下载webkit,我下载的版本最后的 ...

  10. sockaddr_u详解

    struct sockaddr { unsigned short sa_family;     /* address family, AF_xxx */ char sa_data[14];       ...