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. Python超级程序员使用的开发工具

    我以个人的身份采访了几个顶尖的Python程序员,问了他们以下5个简单的问题: 当前你的主要开发任务是什么? 你在项目中使用的电脑是怎样的? 你使用什么IDE开发? 你将来的计划是什么? 有什么给Py ...

  2. Visual Basic相关图书推荐

    Visual Basic从入门到精通(第2版) 作      者 国家863中部软件孵化器 编 出 版 社 人民邮电出版社 出版时间 2015-03-01 版      次 2 页      数 61 ...

  3. PHP相关图书推荐

    PHP和MySQL Web开发(原书第4版) 作      者 [澳] Luke Welling,[澳] Luke Welling 著:武欣 等 译 出 版 社 机械工业出版社 出版时间 2009-0 ...

  4. Eclipse中用Link方式安装Maven插件(转载)

    标签: it 分类: 开发软件 1.工具下载: Eclipse4.2 jee版本(注意是Jee,不是标准版的eclipse) 下载地址:http://www.eclipse.org/downloads ...

  5. 50+ 响应式的Prestashop电商主题

    PrestaShop是一款针对web2.0设计的全功能.跨平台的免费开源电子商务解决方案,自08年1.0版本发布,短短两年时间,发展迅速,全球已超过四万家网店采用Prestashop进行部署.Pres ...

  6. noip模拟赛 软件software

    地图上的 n个城市,由 n-1条道路连接,且任意两个城市连通.除 1号城市之外的每个都有 一台计算机,安装软件号城市之外的每个都有 一台计算机,安装软件一个 自己的安装时间.住在 1号城市的蒟蒻要给这 ...

  7. php和.net 的加密解密

    PHP版: $key = 335ff'; /* * 加密方法 * @param string $input,待加密的字符串 * @param string $key,加密的密码(只能为8位长) * @ ...

  8. MVC Dynamic Authorization--示例市在Action前进行的验证,应提前到Auth过滤器

    Introduction In MVC the default method to perform authorization is hard coding the "Authorize&q ...

  9. Unity3D Script Keynote

    [Unity3D Script Keynote] 1.创建GameObject if(GUILayout.Button("创建立方体",GUILayout.Height(50))) ...

  10. *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL

    kei编译时提示: *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL *** WARNING L1:reference made to unresolved ext ...