poj 1224
题意:有一个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的更多相关文章
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- 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 ...
随机推荐
- Hadoop环境搭建|第一篇:linux操作系统安装
一.安装工具及文件 优盘:8G(非kingston优盘) 制作启动盘工具:Universal_USB_Installer 操作系统:CentOs操作系统 二.注意事项 安装过程的详细步骤,这里就不再赘 ...
- Leetcode题目292.Nim游戏(脑筋急转弯)
题目描述: 你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解. 编写一个 ...
- Java core dump
目录 生成Java core dump core dump分析 生成Java core dump 可以按照下面这个文章的指引来通过jni调用触发Java core dump Generating a ...
- Eclipse的视窗
PackageExplorer 显示项目结构,包,类,及资源 Outline 显示类的结构,方便查找,识别,修改 Console 程序运行的结果在该窗口显示 Hierarchy 显示Java继承层次结 ...
- 关于Jetson Kit开发相关资料
首先是nVidia官方对于Jetson Kit的介绍: http://www.nvidia.com/object/jetson-tk1-embedded-dev-kit.html https://de ...
- 阶段5 3.微服务项目【学成在线】_day04 页面静态化_24-页面预览-页面预览测试
通过nginx转发到预览的地址 重启nginx 添加页面预览按钮 调整下列表的列的宽度
- python抽取指定url页面的title方法
python抽取指定url页面的title方法 今天简单使用了一下python的re模块和lxml模块,分别利用的它们提供的正则表达式和xpath来解析页面源码从中提取所需的title,xpath在完 ...
- python基础--字符串、元组
字符串方法 注:字符串和元组一样都是不可变的,以下函数不会改变原来字符串的值,可以将其赋给一个新的变量 st='a b c d,f,g' st_list=st.split()#字符串分割,参数不写,按 ...
- unicode 字符范围
根据最新的Unicode 5.0版整理如下: 1)标准CJK文字 http://www.unicode.org/Public/UNIDATA/Unihan.html Code point range ...
- IEEE754二进制浮点数算术标准
对于32位浮点数 sign: 符号,1位 exponent: 指数,8位,偏码 fraction: 分数,23位,原码 特殊值 指数域的编码值 = 指数的实际值 + 127 这样按照字典序的顺序就 ...