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. Unreal Engine 虚幻引擎宣布对开发者免费

    虚幻引擎4现在可供每个人免费使用,而且所有未来的更新都将免费!您可以下载引擎并将其用于游戏开发的各个方面,包括教育.建筑以及可视化,甚至虚拟现 实.电影和动画. 当您发布游戏或应用时,在您的每个游戏在 ...

  2. 【leetcode】155 - Min Stack

    Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...

  3. 【转】Android Intent Action 大全

    String ADD_SHORTCUT_ACTION 动作:在系统中添加一个快捷方式.. “android.intent.action.ADD_SHORTCUT” String ALL_APPS_AC ...

  4. Embedded之memory type

    1 Types of memory 2 Characteristics

  5. 60个响应式的Web设计教程–能够手机访问!

    想要学习响应式[responsive:屏幕自适应的效果]的网页设计和开发技术?在这个超大的收藏集合中,我想你定会找到想要开始学习的响应式网页设计教程. 面对超过1亿的手机互联网用户,开发专业和用户友好 ...

  6. Python的数据处理学习(三)

    三.类的继承   Python 的class可以允许从零开始创建一个定制类,就像文章(二)创建Athlete类一样,也可以通过继承现有的其他类类创建一个类,这也包括用List.set和dict提供的p ...

  7. 使用gdb调试多线程程序总结

    转:使用gdb调试多线程程序总结 一直对GDB多线程调试接触不多,最近因为工作有了一些接触,简单作点记录吧. 先介绍一下GDB多线程调试的基本命令. info threads 显示当前可调试的所有线程 ...

  8. 服务框架Dubbo(转)

    add by zhj:该开源项目已经停止更新了,不过倒是可以学学该软件的架构设计 原文:http://www.oschina.net/p/dubbo Dubbo 是阿里巴巴公司开源的一个高性能优秀的服 ...

  9. [转]Torch是什么?

    Torch是一个广泛支持机器学习算法的科学计算框架.易于使用且高效,主要得益于一个简单的和快速的脚本语言LuaJIT,和底层的C / CUDA实现:Torch | Github 核心特征的总结:1. ...

  10. lght oj 1257 - Farthest Nodes in a Tree (II) (树dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1257 跟hdu2196一样,两次dfs //#pragma comment(l ...