http://poj.org/problem?id=1222

题意:给一个确定的5*6放入矩阵。每一个格子都有一个开关和一盏灯,0表示灯没亮,1表示灯亮着。让你输出一个5*6的矩阵ans[i][j],ans[i][j] = 1表示按下开关,ans[i][j] = 0表示不按开关,使最后全部的灯都熄灭。



思路:与http://acm.hdu.edu.cn/showproblem.php?pid=1882类似。在这里找到一种方案输出就可以。但有一个疑惑不解。最后ans[ ][ ]输出的时候每一行里要倒着输出。。。

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#define LL long long
#define _LL __int64
using namespace std;
const int INF = 0x3f3f3f3f; int map[7][7];
int sta[7],tmp[7];
int ans[7][7];
int bit[8] = {1,2,4,8,16,32,64,128}; void solve()
{
for(int i = 0; i < (1<<6); i++)
{
memcpy(tmp,sta,sizeof(sta));
memset(ans,0,sizeof(ans)); for(int j = 0; j < 6; j++)
{
if(bit[j]&i)
{
ans[0][j] = 1;
if(j > 0)
tmp[0] ^= bit[j-1];
if(j < 5)
tmp[0] ^= bit[j+1];
tmp[0] ^= bit[j];
tmp[1] ^= bit[j];
}
} for(int j = 1; j < 5; j++)
{
for(int k = 0; k < 6; k++)
{
if(bit[k]&tmp[j-1])
{
ans[j][k] = 1;
if(k > 0)
tmp[j] ^= bit[k-1];
if(k < 5)
tmp[j] ^= bit[k+1];
tmp[j] ^= bit[k];
tmp[j+1] ^= bit[k];
}
}
}
if(!tmp[4])
{
for(int i = 0; i < 5; i++)
{
for(int j = 5; j > 0; j--)
printf("%d ",ans[i][j]);
printf("%d\n",ans[i][0]);
}
break;
} }
} int main()
{
int test;
scanf("%d",&test);
int item = 1;
while(test--)
{
memset(sta,0,sizeof(sta));
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 6; j++)
{
scanf("%d",&map[i][j]);
if(map[i][j] == 0)
sta[i] <<= 1;
else sta[i] = (sta[i]<<1)+1;
}
}
printf("PUZZLE #%d\n",item++);
solve();
}
return 0; }

poj 1222 EXTENDED LIGHTS OUT(位运算+枚举)的更多相关文章

  1. POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)

    POJ 1222 EXTENDED LIGHTS OUT 今天真是完美的一天,这是我在poj上的100A,留个纪念,马上就要期中考试了,可能后面几周刷题就没这么快了,不管怎样,为下一个200A奋斗, ...

  2. POJ 1222 EXTENDED LIGHTS OUT(高斯消元解异或方程组)

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10835   Accepted: 6 ...

  3. POJ 1222 EXTENDED LIGHTS OUT(反转)

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12616   Accepted: 8 ...

  4. Poj 1222 EXTENDED LIGHTS OUT

    题目大意:给你一个5*6的格子,每个格子中有灯(亮着1,暗着0),每次你可以把一个暗的点亮(或者亮的熄灭)然后它上下左右的灯也会跟着变化.最后让你把所有的灯熄灭,问你应该改变哪些灯. 首先我们可以发现 ...

  5. POJ 1222 EXTENDED LIGHTS OUT(高斯消元)题解

    题意:5*6的格子,你翻一个地方,那么这个地方和上下左右的格子都会翻面,要求把所有为1的格子翻成0,输出一个5*6的矩阵,把要翻的赋值1,不翻的0,每个格子只翻1次 思路:poj 1222 高斯消元详 ...

  6. 【高斯消元】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 ...

  7. OpenJudge 2811 熄灯问题 / Poj 1222 EXTENDED LIGHTS OUT

    1.链接地址: http://bailian.openjudge.cn/practice/2811 http://poj.org/problem?id=1222 2.题目: 总时间限制: 1000ms ...

  8. POJ 1222 EXTENDED LIGHTS OUT(高斯消元)

    [题目链接] http://poj.org/problem?id=1222 [题目大意] 给出一个6*5的矩阵,由0和1构成,要求将其全部变成0,每个格子和周围的四个格子联动,就是说,如果一个格子变了 ...

  9. POJ 1222 EXTENDED LIGHTS OUT (熄灯问题)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8417   Accepted: 5441 Description In an ...

随机推荐

  1. linux 为开机菜单加密码·

    首先是在/boot/grub/menu.lst 里面添加密码的,但是需要是加密过后的,否则人家直接跑到你的menu.lst里面查看密码不就行了.... 于是,可以使用grub提供的md5加密功能: # ...

  2. MyEclipse2015对Javascript自动提示的终极支持

    2015通过集成Tern.js,进入了JS自动提示的最新时代 先看看具体效果吧:   点击链接会进入:   而tern.js已经支持相当多的框架:   关键这个提示不只是纯粹的js文件,对于jsp等等 ...

  3. BestCoder Round #88

    传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...

  4. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. 【Excel】Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046}:

    [Excel]Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-0000000000 ...

  6. CMake编译linux C++

    CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的 ...

  7. Struts2数据校验方法

    方法: 1.在Action类中execute()方法中进行校验. 优点:Action类无需继承框架中的类. 缺点:(1)当有多个校验时,代码重复,违反高内聚,低耦合. 2.重写框架ActionSupp ...

  8. mac电脑Coding显示/隐藏文件

    苹果Mac OS X操作系统下,隐藏文件是否显示有很多种设置方法,最简单的要算在Mac终端输入命令.显示/隐藏Mac隐藏文件命令如下(注意其中的空格并且区分大小写): 显示Mac隐藏文件的命令:def ...

  9. JAVA大数运算

    java大数是个好东西,用起来方便,代码短. 代码如下: import java.util.*; import java.math.*; public class Main { public stat ...

  10. Android 显示/隐藏 应用图标

    PackageManager packageManager = getPackageManager(); ComponentName componentName = new ComponentName ...