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 ...
随机推荐
- flask 自定义转换器
from flask import Flask from flask import url_for from flask import redirect from werkzeug.routing i ...
- Jmeter Web 性能测试入门 (三):Jmeter 常用组件说明
线程组:用来设置并发的数量和模式.是用来模拟用户并发的组件.JMeter 的每个任务都是用线程来处理的. 线程数:要并发的请求数量. Ramp-Up Period: 在多次时间内把这些并发的请求发送完 ...
- docker 容器连接 host的sql server失败
报错内容::“A network-related or instance-specific error occurred while establishing a connection to SQL ...
- 电路IO驱动能力
驱动能力 电源驱动能力 -> 输出电流能力 -> 输出电阻 指输出电流的能力,比如芯片的IO在高电平时的最大输出电流是4mA -> 该IO口的驱动驱动能力为4mA 负载过大(小电阻) ...
- java课后实验性问题5
课后作业一:字符串加密 程序设计思想: 从键盘获取字符串,将字符串转为字符数组,将每个元素加事前协定的“key”,再转为字符串输出. 程序流程图: 源代码: import java.util.Scan ...
- DBCA创建数据库
工具/原料 oracle database 11g 步骤/方法 1 确保安装好oracle database 11g 2 打开命令提示符(运行中输入CMD打开 或是在 附件中点击打开) 3 输入dbc ...
- How to appraise Hearthstone card values
https://elie.net/blog/hearthstone/how-to-appraise-hearthstone-card-values/ In 2014, I became an avid ...
- Mysql mysqldumpslow命令详解
mysqldumpslow命令 /path/mysqldumpslow -s c -t 10 /database/mysql/slow-log 这会输出记录次数最多的10条SQL语句. 其中: -s, ...
- UML期末复习题
看了网上的各种UML图的相关资料,找到的都是差不多一样的对图的基本介绍.之前复习的时候也想对不同UML图单独进行复习总结,后来发现这样复习好像没什么用,不能理解每个图之间的关系,所以就没有进一步总结. ...
- GPS模块编程之NMEA0183协议
NMEA 0183是美国国家海洋电子协会(National Marine Electronics Association)为海用电子设备制定的标准格式.现在已经成为GPS导航设备统一的RTCM(Rad ...