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

#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. ZOJ 2158 POJ 1789 Truck History

    最小生成树,主要是题目比较难懂. #include <cstdio> #include <cstring> #include <cmath> #include &l ...

  2. YII2 运行概述(Overview)

    运行机制概述 每一次 Yii 应用开始处理 HTTP 请求时,它都会进行一个近似的流程. 用户提交指向 入口脚本 web/index.php 的请求. 入口脚本会加载 配置数组 并创建一个 应用 实例 ...

  3. hdu_5783_Divide the Sequence(贪心)

    题目链接:hdu_5783_Divide the Sequence 题意: 给你一个数列,让你分尽可能多的段,并且保证每一段的前缀和都不小于0 题解: 从后往前xjb贪心就行了 #include< ...

  4. LeetCode OJ 95. Unique Binary Search Trees II

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

  5. 关于Spring Security 3获取用户信息的问题

    标签: spring security 3标签获取用户信息 2013-01-05 10:40 5342人阅读 评论(0) 收藏 举报  分类: Spring(25) java(70) 前端(7)    ...

  6. Ansible6:Playbook简单使用【转】

    ansbile-playbook是一系列ansible命令的集合,利用yaml 语言编写.playbook命令根据自上而下的顺序依次执行.同时,playbook开创了很多特性,它可以允许你传输某个命令 ...

  7. 1.java.io包中定义了多个流类型来实现输入和输出功能,

    1.java.io包中定义了多个流类型来实现输入和输出功能,可以从不同的角度对其进行分 类,按功能分为:(C),如果为读取的内容进行处理后再输出,需要使用下列哪种流?(G)   A.输入流和输出流 B ...

  8. 拓扑序+dp Codeforces Round #374 (Div. 2) C

    http://codeforces.com/contest/721/problem/C 题目大意:给你有向路,每条路都有一个权值t,你从1走到n,最多花费不能超过T,问在T时间内最多能访问多少城市? ...

  9. flex日期合并与拆分

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  10. js冒泡事件小解

    何为冒泡事件?简单来说事件就像一个水里的泡泡,先触发当前对象再触发其父元素,然后是父元素的父元素... eg: <div class="out" onclick= " ...