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 ...
随机推荐
- 对@repository,@Service, @Compent,@Controller注解的理解
注解是没什么本质区别,都是声明作用,取不同的名字只是为了更好区分各自的功能. @Repository 用于标注数据访问组件,即DAO组件 @Service 用于标注业务层组件 @Controller ...
- java基础篇之Object类
1.Object类是所有类的超类 2.Object类的equals方法 public boolean equals(Object obj) {return (this == obj);} equals ...
- 定位ScheduledExecutorService过了一段时间不执行问题
今天查看生产环境的sentinel控制台,发现某dubbo应用一共5个节点,有3个失联了. 查看失联节点的应用日志,服务没有挂,各dubbo接口的日志正常在打印. 在应用节点ping/telnet s ...
- linux内核中的wait_event_interruptible_timeout接口解析
1. 原型 #define wait_event_interruptible_timeout(wq_head, condition, timeout) \ ({ \ long __ret = time ...
- linux中如何配置vim的别名为vi?
答: 向~/.bashrc中添加如下内容: alias vi=vim
- StateListDrawable
可供设置的属性如下: drawable:引用的Drawable位图,我们可以把他放到最前面,就表示组件的正常状态~ state_focused:是否获得焦点 state_window_focused: ...
- c# 线程异步处理
public class AsyncHelper { private static readonly TaskFactory _myTaskFactory = new TaskFactory(Canc ...
- Vue打包文件放在服务器后,浏览器存在缓存问题
每次打包更新版本发到服务器上,导致偶尔会出现不能即使更新最新代码,浏览器存在缓存的问题. 解决方法:找到webpack .prod.conf.js 1.定义版本变量: const Version = ...
- MATLAB常用快捷键总结
MATLAB 命令栏显示处理的常用命令 清屏:clc 紧凑显示格式:format compact 宽松显示格式:format loose 数据高精度显示:format longG 数据低精度显示:fo ...
- Goland 激活码
实测有效,分享下 Goland