题意:有一个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. 第11组 Beta冲刺(5/5)

    第11组 Beta冲刺(5/5)   队名 不知道叫什么团队 组长博客 https://www.cnblogs.com/xxylac/p/12031050.html 作业博客 https://edu. ...

  2. nodeJS 项目如何运行

    nodeJS 项目如何运行 一.总结 一句话总结: nodejs项目根目录中用node xx.js 或是 node xx运行 打开 window的 cmd 命令窗口,使用 cd 命令跳转到 nodeJ ...

  3. PHP多进程开发与Redis结合实践

    原文:https://blog.51cto.com/laok8/2107892?source=drh 业务逻辑介绍: 用户在 APP 上发帖子,然后存储到 Redis 的 List 列表中 利用 Li ...

  4. 配置nginx支持path_info

    默认情况下,nginx是不支持path_info的,我们需要做些配置让它支持. location ~ \.php(.*)$ { root /var/www/nginx/html; fastcgi_pa ...

  5. tomcat部署web项目的问题

    1:启动窗口乱码 原因 Tomcat默认都是UTF-8的,但是控制台是GBK的,要保持一致 解决办法 打开tomcat目录下的conf/目录下logging.properties找到java.util ...

  6. Unix/Linux下如何查看DNS服务器地址

    使用命令: cat /etc/resolv.conf 或者 less /etc/resolv.conf 即可. 详细请见:http://www.cyberciti.biz/faq/how-to-fin ...

  7. post请求导出Excel表格

    axios.interceptors.response.use((response) =>{ if(response.config && response.config.resp ...

  8. mfc移动文件夹

    SHFILEOPSTRUCT FileOp; ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT)); FileOp.fFlags = FOF_NO ...

  9. LeetCode_13. Roman to Integer

    13. Roman to Integer Easy Roman numerals are represented by seven different symbols: I, V, X, L, C,  ...

  10. 如何在ubuntu下重建被grub覆盖的win10引导区?

    如何在ubuntu下重建被grub覆盖的win10引导区? 1.修改grub配置文件: sudo vi /etc/default/grub 2.设置:GRUB_DEFAULT = 2 3.更新配置文件 ...