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

思路:poj 1222 高斯消元详解

代码:

#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define eps 1e-9
typedef long long ll;
const int maxn = 1e4 + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
int a[][], x[], Case = ;
int equ, var;
int free_num,free_x[];
int Gauss(){
int max_r, col, k;
free_num = ;
equ = var = ;
for(k = , col = ; k < equ && col < var; k++, col++){
max_r = k;
for(int i = k + ; i < equ; i++){
if(abs(a[i][col]) > abs(a[max_r][col]))
max_r = i;
}
if(a[max_r][col] == ){
k--;
free_x[free_num++] = col;
continue;
}
if(max_r != k){
for(int j = col; j < var + ; j++){
swap(a[k][j], a[max_r][j]);
}
}
for(int i = k + ; i < equ; i++){
if(a[i][col] != ){
for(int j = col; j < var + ; j++){
a[i][j] ^= a[k][j];
}
}
}
}
for(int i = k; i < equ; i++){
if(a[i][col] != )
return -;
}
if(k < var) return var - k;
for(int i = var - ; i >= ; i--){
x[i] = a[i][var];
for(int j = i + ; j < var; j++){
x[i] ^= (a[i][j] & x[j]);
}
}
return ;
}
int pos(int i, int j){
return i * + j;
}
void solve(){
int u;
memset(a, , sizeof(a));
memset(x, , sizeof(x));
for(int i = ; i < ; i++){
for(int j = ; j < ; j++){
if(i > ) a[pos(i - , j)][pos(i, j)] = ;
if(i < ) a[pos(i + , j)][pos(i, j)] = ;
if(j > ) a[pos(i, j - )][pos(i, j)] = ;
if(j < ) a[pos(i, j + )][pos(i, j)] = ;
a[pos(i, j)][pos(i, j)] = ;
int u;
scanf("%d", &u);
a[pos(i, j)][] = u;
}
}
Gauss();
printf("PUZZLE #%d\n", Case++);
for(int i = ; i < ; i++){
for(int j = ; j < ; j++){
if(j != ) printf(" ");
printf("%d", x[pos(i, j)]);
}
printf("\n");
}
}
int main(){
int T;
scanf("%d", &T);
while(T--){
solve();
}
return ;
}

POJ 1222 EXTENDED LIGHTS OUT(高斯消元)题解的更多相关文章

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

    题目链接 题意:5*6矩阵中有30个灯,操作一个灯,周围的上下左右四个灯会发生相应变化 即由灭变亮,由亮变灭,如何操作使灯全灭? 题解:这个问题是很经典的高斯消元问题.同一个按钮最多只能被按一次,因为 ...

  2. POJ 1222 EXTENDED LIGHTS OUT [高斯消元XOR]

    题意: $5*6$网格里有一些灯告诉你一开始开关状态,按一盏灯会改变它及其上下左右的状态,问最后全熄灭需要按那些灯,保证有解 经典问题 一盏灯最多会被按一次,并且有很明显的异或性质 一个灯作为一个方程 ...

  3. poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8481   Accepted: 5479 Description In an ...

  4. POJ1222 EXTENDED LIGHTS OUT 高斯消元 XOR方程组

    http://poj.org/problem?id=1222 在学校oj用搜索写了一次,这次写高斯消元,haoi现场裸xor方程消元没写出来,真实zz. #include<iostream> ...

  5. POJ 1222【异或高斯消元|二进制状态枚举】

    题目链接:[http://poj.org/problem?id=1222] 题意:Light Out,给出一个5 * 6的0,1矩阵,0表示灯熄灭,反之为灯亮.输出一种方案,使得所有的等都被熄灭. 题 ...

  6. POJ 1222 熄灯问题【高斯消元】

    <题目链接> 题目大意: 有一个5*6的矩阵,每一位是0或者1. 没翻转一位,它的上下左右的数字也为改变.(0变成1,1变成0).要把矩阵中所有的数都变成0.求最少翻转次数的方案,输出矩阵 ...

  7. [poj1222]EXTENDED LIGHTS OUT(高斯消元)

    题意:每个灯开启会使自身和周围的灯反转,要使全图的灯灭掉,判断灯开的位置. 解题关键:二进制高斯消元模板题. 复杂度:$O({n^3})$ #include<cstdio> #includ ...

  8. EXTENDED LIGHTS OUT (高斯消元)

    In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each (the actual ...

  9. POJ 1681---Painter's Problem(高斯消元)

    POJ   1681---Painter's Problem(高斯消元) Description There is a square wall which is made of n*n small s ...

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

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

随机推荐

  1. android studio 1

    1.继承activity类的时候,重写父类 @Override   //伪代码 ,代表如果不是重写父类的方法,该地方会报错 protected void onCreate( Bundle savedI ...

  2. layer,一个可以让你想到即可做到的javascript弹窗(层)解决方案

    学习网址:http://layer.layui.com/ 下载地址:http://res.layui.com/download/layer-v2.1.zip 我们提到的基础参数主要指调用方法时用到的配 ...

  3. 包含.h就可以用其对应的函数

    //callee.h 被调用者 #pragma once void display(); //展示函数 //callee.cpp 被调用者 #include "callee.h" ...

  4. 【Cocos2dx 3.3 Lua】导出Cocos2dx API文档

    一.Doxygen导出Cocos2dx html doc              1.1 打开Doxygen软件,选择 File-->Open打开Cocos2dx docs目录下的doxyge ...

  5. 蒙特卡洛模拟(Monte Carlo simulation)

    1.蒙特卡罗模拟简介 蒙特卡罗模拟,也叫统计模拟,这个术语是二战时期美国物理学家Metropolis执行曼哈顿计划的过程中提出来的,其基本思想很早以前就被人们所发现和利用.早在17世纪,人们就知道用事 ...

  6. python图片处理(一)

    python图片处理需要先在cmd里面安装Pillow pip install Pillow 一.图片的打开与显示 from PIL import Image img=Image.open('d:/d ...

  7. linux命令:linux权限管理命令

    权限管理命令   文件的权限只有你两个人可以更改,一个是root,一个是文件所有者. 命令名称:chmod 命令英文原意:change the permissions mode of a  file ...

  8. js实现网页tab选项卡切换效果

    <style> *{margin:0;padding:0;} body{font-size:14px;font-family:"Microsoft YaHei";} u ...

  9. 019-centos的yum用法

    1.检测系统是否已经安装过mysql或其依赖:# yum list installed | grep mysql(当然也可以用 rpm -qa | grep mysql) 2.卸载已经存在的mysql ...

  10. Object-C-selector

    Shape *shape=[[Shape alloc]init]; //[shape draw] SEL selDraw=@selector(draw); [shape performSelector ...