题意:有一个5 * 6的矩阵,每个位置表示灯,1表示灯亮,0表示灯灭。 
然后如果选定位置i,j点击,则位置i,j和其上下左右的灯的状态都会反转。 
现在要你求出一个5 * 6的矩阵,1表示这个灯被点击过,0表示没有。 
要求这个矩阵能够使得原矩阵的灯全灭。

题解:构造一个30 X 31增广矩阵(一个有30个目标结果,所以方程组的个数为30,然后可用的变量个数为30 ,增广一下就是30 X 31了)然后异或高斯就可以了。

ac代码:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int dir[][]={{,},{,-},{,},{-,}};
int mp[][];
int x[];
int a[][];
void init()
{
memset(x,,sizeof(x));
memset(a,,sizeof(a));
}
int check(int x,int y)
{
if(x<= || x>= || y<= || y>=) return -;
return ;
}
void Debug(int n,int m)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++) cout<<a[i][j]<<' ';
cout<<endl;
}
}
void gauss()
{
int max_r;
int col,k;
int i,j;
for(int z=;z<=;z++)
{
for(int zz=;zz<=;zz++)
{
i=(z-)*+zz;// row
j=(z-)*+zz;
a[i][]=mp[z][zz];
a[i][j]=;
for(int low=;low<;low++)// 里面的一一对应 求集中注意力写/。。。
{
int xx=z+dir[low][];
int yy=zz+dir[low][];
if(check(xx,yy)==) //attention !! 这个条件都写错了,, 里面不成立写的是-1 所以外面要注意一点。。
{
j=(xx-)*+yy;
// cout<<low<<' '<<xx<<' '<<yy<<endl;
a[i][j]=;
}
}
}
} // Debug(30,31);
col=k=;
while( k<= && col<=) // 阶梯化
{
max_r=k;
for(int u=k;u<=;u++) if(a[u][col])
{
max_r=u; // find max
break;
}
if(a[max_r][col]!=)
{
if(max_r!=k) // not the frist ont swap it
{
for(int u=;u<=;u++) swap(a[max_r][u],a[k][u]);
}
for(int u=k+;u<=;u++)
{
if(a[u][col])
{
for(int z=;z<=;z++) a[u][z]^=a[k][z];
}
}
k++;
}
col++;
}
//Debug(30,31);
int temp=;
for(int z=;z>=;z--)
{
x[z]=a[z][];
for(int zz=z+;zz<=;zz++) if(a[z][zz])
{
x[z]^=x[zz];
}
}
}
int main()
{
int t;
scanf("%d",&t);
int Case=;
while(t--)
{
for(int i=;i<=;i++)
{
for(int j=;j<=;j++) scanf("%d",&mp[i][j]);
}
init();//a x
gauss(); // 还有一个点 就是方程的构造问题
printf("PUZZLE #%d\n",++Case);
for(int i=;i<=;i++)
{
if(i%!=) printf("%d ",x[i]);
else printf("%d\n",x[i]);
}
}
return ;
}

poj 1224的更多相关文章

  1. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  2. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  3. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  4. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  5. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  6. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  7. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  8. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  9. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

随机推荐

  1. dpkg 删除 百度网盘 程序

    sudo dpkg -l baidu* 查询得到具体名字 sudo dpkg --purge baidunetdisk 解决

  2. nginx使用certbot配置https

    一般现在的网站都要支持https,即安全的http. 机器:阿里云Ubuntu 16.04.3 LTS 方案一:自己申请证书 配置时需要确保有ssl模块, 之后域名解析下, 之后时申请证书,可以去阿里 ...

  3. SpringMVC返回Map类型转换成JSON失败

    错误信息:WARN DefaultHandlerExceptionResolver:380 - Failed to write HTTP message: org.springframework.ht ...

  4. css简单学习属性

      1:内联元素和块级元素 1).块级元素,默认是:内联元素可以变成块级元素,块级元素可以变成内联元素. <!DOCTYPE html> <html lang="en&qu ...

  5. Win10安装多个MySQL实例

    Win10安装MySQL-8.0.15 1.下载mysql-8.0.15-winx64.zip安装包,地址如下 https://cdn.mysql.com//Downloads/MySQL-8.0/m ...

  6. Java 实现 bash命令

    Java 实现 bash命令 1.BASH 命令简介 Bash,Unix shell的一种,在1987年由布莱恩·福克斯为了GNU计划而编写.1989年发布第一个正式版本,原先是计划用在GNU操作系统 ...

  7. 三种单点登录SSO的实现原理

    单点登录SSO(Single Sign On)说得简单点就是在一个多系统共存的环境下,用户在一处登录后,就不用在其他系统中登录,也就是用户的一次登录能得到其他所有系统的信任.单点登录在大型网站里使用得 ...

  8. HAProxy+Keepalived 高可用负载均衡

    转自 https://www.jianshu.com/p/95cc6e875456 Keepalived+haproxy实现高可用负载均衡 Master backup vip(虚拟IP) 192.16 ...

  9. Spring Security(2):过滤器链(filter chain)的介绍

    上一节中,主要讲了Spring Security认证和授权的核心组件及核心方法.但是,什么时候调用这些方法呢?答案就是Filter和AOP.Spring Security在我们进行用户认证以及授予权限 ...

  10. HANA数据自助查询

    SAP HANA的客户端是C/S模式的,远程使用不太方便,目前有一款TreeSoft数据库管理系统,可以实现通过web方式,访问自助查询HANA数据.大大提高工作效率.还支持MySQL,Oracle, ...