Enum:EXTENDED LIGHTS OUT(POJ 1222)

题目大意:有一个5*6的灯组,按一盏灯会让其他上下左右4栈和他自己灯变为原来相反的状态,要怎么按才会把所有的灯都按灭?
3279翻版题目,不多说,另外这一题还可以用其他方法,比如DFS,BFS,不过这些都挺慢的,月还有一个特别厉害的方法,高斯消元法,等我以后再来写
#include <iostream>
#include <algorithm>
#include <functional> using namespace std; static int map[][], store[][], flip[][];
static int dirx[] = { -, , , };
static int diry[] = { , -, , }; int solve(void);
int get_light(const int, const int); int main(void)
{
int sum_of_martrix, ans, res;
scanf("%d", &sum_of_martrix); for (int k = ; k <= sum_of_martrix;k++)
{
ans = INT_MAX;
for (int i = ; i < ; i++)//Read Gragh
for (int j = ; j < ; j++)
scanf("%d", &map[i][j]); for (int i = ; i < << ; i++)
{
memset(flip, , sizeof(flip));
for (int j = ; j < ; j++)
flip[][ - j] = (i >> j) & ;
res = solve();
if (res < ans)
{
ans = res;
memcpy(store, flip, sizeof(flip));
}
}
printf("PUZZLE #%d\n", k);
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
printf("%d ", store[i][j]);
printf("\n");
}
}
return EXIT_SUCCESS;
} int solve(void)
{
int ans = ;
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
flip[i][j] = get_light(i - , j);//如果这一列的上一行是亮灯,那么必须按下这盏灯 for (int j = ; j < ; j++)
{
if (get_light(, j) == )//看最后一行的灯的情况是否全部灯都灭了
return INT_MAX;
} for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
ans += flip[i][j];
return ans;
} int get_light(const int y, const int x)
{
int dx, dy, sum = map[y][x]; for (int i = ; i < ; i++)
{
dx = x + dirx[i]; dy = y + diry[i];
if ( <= dx && dx < && <= dy && dy < )
sum += flip[dy][dx];
}
return sum % ;
}

Enum:EXTENDED LIGHTS OUT(POJ 1222)的更多相关文章
- POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)
POJ 1222 EXTENDED LIGHTS OUT 今天真是完美的一天,这是我在poj上的100A,留个纪念,马上就要期中考试了,可能后面几周刷题就没这么快了,不管怎样,为下一个200A奋斗, ...
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元解异或方程组)
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10835 Accepted: 6 ...
- Poj 1222 EXTENDED LIGHTS OUT
题目大意:给你一个5*6的格子,每个格子中有灯(亮着1,暗着0),每次你可以把一个暗的点亮(或者亮的熄灭)然后它上下左右的灯也会跟着变化.最后让你把所有的灯熄灭,问你应该改变哪些灯. 首先我们可以发现 ...
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元)题解
题意:5*6的格子,你翻一个地方,那么这个地方和上下左右的格子都会翻面,要求把所有为1的格子翻成0,输出一个5*6的矩阵,把要翻的赋值1,不翻的0,每个格子只翻1次 思路:poj 1222 高斯消元详 ...
- POJ 1222 EXTENDED LIGHTS OUT(反转)
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12616 Accepted: 8 ...
- 【POJ】1222 EXTENDED LIGHTS OUT
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...
- POJ 1222 POJ 1830 POJ 1681 POJ 1753 POJ 3185 高斯消元求解一类开关问题
http://poj.org/problem?id=1222 http://poj.org/problem?id=1830 http://poj.org/problem?id=1681 http:// ...
- *POJ 1222 高斯消元
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9612 Accepted: 62 ...
- POJ 1222
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6196 Accepted: 40 ...
随机推荐
- hdu4920 Matrix multiplication 模3矩阵乘法
hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- JS抽奖功能代码
HTML <label for="awardListDom">奖项列表</label><br> <input type="tex ...
- 详解CSS中clear属性both、left、right值的含义
前几天一朋友在群里问clear:left的意思,我以为是简单的清除浮动问题,就让他百度"清除浮动",导致中间有点小误会.后来我按照他写的DEMO,发现我自己也没完全理解clear: ...
- HDU 2014
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> typedef float ElementType; void Select_Sort ...
- 按下enter键后表单自动提交问题
在HTML的form表单里,按下enter键之后,默认情况下表单会自动提交. 在公司一个项目里,按下enter键自动提交表单的查询结果与按下搜索框的搜索结果页面显示不一样,按下搜索按钮之后是通过Aja ...
- 【bzoj1036】[ZJOI2008]树的统计Count
题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w.我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. QMAX u v ...
- lua练手基础
lua的库文件地址: http://luaforge.net/projects/lua官网 http://lua.org --[[ print string. multiple line commen ...
- UNIX Time 时间戳 与 北京时间 相互转换
typedef struct t_xtime { int year; int month; int day; int hour; int minute; int second; } _xtime ; ...
- js搜索框输入提示(高效-ys8)
<style type="text/css"> .inputbox .seleDiv { border: 1px solid #CCCCCC; display: non ...
- Divide Two Integers
视频讲解 http://v.youku.com/v_show/id_XMTY1MTAyODM3Ng==.html int 范围: Integer.MIN_VALUE => -214748364 ...