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主机的几种方法

    方法一,在终端上利用ssh,不登录远程主机,直接发送重启命令 ssh root@192.168.8.128 'reboot' 方法二,在终端上利用ssh和here document ssh root@ ...

  2. linux 后台运行程序

    有些时候,我们需要在终端启动一个程序,并使之运行--但是如果关闭终端,那么这个程序也就随着关闭了.那么有没有什么方法在关闭终端后,让已经从这个终端启动的程序继续运行呢? 前置知识: xterm,con ...

  3. 第一个自定义HTML网页

    前言 已经好几天没玩LOL了,实在手痒,下载了游戏,又卸载了,坦言:毛爷爷说的”好好天天向上“,真不容易.但还是回到学习个状态了,开始写,就“根本停不下来”,我也慢慢感受到代码的快乐了,并且想总结出一 ...

  4. sudo 权限问题

    窝里个去,不使用sudo吧rvm requirements执行不成功.加上sudo吧rvm requirements调用的brew install又不行.好吧,就按上面说的将brew转换到root模式 ...

  5. cocos2d-html5将js编译为jsc

    在d:\DevTool\cocos2d-x-2.2.2\cocos2d-x-2.2.2\tools\cocos2d-console\console 有 cocos2d_jscompile.py coc ...

  6. Android Studio 中SDK Manager的设置

    android studio 代码块左边的缩进对齐线的颜色修改:  Settings -> Editor -> Colors & Fonts -> General -> ...

  7. ubuntu 彻底删除软件包

    找到此软件名称,然后sudo apt-get purge ......(点点为为程序名称),purge参数为彻底删除文件,然后sudo apt-get autoremove,sudo apt-get ...

  8. 第二百零五天 how can I 坚持

    身体无论什么时候都是最重要的.肝血管瘤,头一次听说,应该没什么大碍.父母年龄大了,我们也该尽快把自己的事情处理好,让他们放心了. 规律作息,合理饮食,多注意锻炼. 该怎么办.不能这拖下去. 好好规划下 ...

  9. -ms-viewport的问题

    Windows 8 中的 Internet Explorer 10 和 Windows Phone 8 Internet Explorer 10 doesn't differentiate devic ...

  10. centos安装lxml和pyspider

    yum -y install --nogpgcheck python34u-devel.x86_64 yum -y install libcurl-devel yum -y install libxs ...