同上题


需要判断无解

需要求最小按几次,正确做法是枚举自由元的所有取值来遍历变量的所有取值取合法的最小值,然而听说数据太弱自由元全0就可以就水过去吧....

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace std;
const int N=;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,t;
bitset<N> a[N];
void ini(){
for(int i=;i<=n;i++) a[i].reset();
}
char s[N];
void Gauss(){
int now=;
for(int i=;i<=n;i++){
int j=now;
while(j<=n&&!a[j][i]) j++;
if(j==n+) continue;
if(now!=j) swap(a[now],a[j]);
for(int k=;k<=n;k++)
if(k!=now&&a[k][i]) a[k]^=a[now];
now++;
}
}
int main(){
freopen("in","r",stdin);
int T=read();
while(T--){
t=read();n=t*t;
ini();
for(int i=;i<=t;i++){
scanf("%s",s+);
for(int j=;j<=t;j++){
int id=(i-)*t+j;
a[id][id]=;
if(i!=) a[id][id-t]=;
if(i!=t) a[id][id+t]=;
if(j!=) a[id][id-]=;
if(j!=t) a[id][id+]=;
a[id][n+]=s[j]=='w';
}
}
Gauss();
int ans=,flag=;
for(int i=;i<=n;i++){
if(a[i][n+]){
int f=;
for(int j=;j<=n;j++) if(a[i][j]==) f=;
if(f==) {flag=;break;}
}
ans+=a[i][n+];
}
if(flag) puts("inf");
else printf("%d\n",ans);
}
}

POJ 1681 Painter's Problem [高斯消元XOR]的更多相关文章

  1. POJ 1681 Painter's Problem (高斯消元)

    题目链接 题意:有一面墙每个格子有黄白两种颜色,刷墙每次刷一格会将上下左右中五个格子变色,求最少的刷方法使得所有的格子都变成yellow. 题解:通过打表我们可以得知4*4的一共有4个自由变元,那么我 ...

  2. POJ 1222 EXTENDED LIGHTS OUT [高斯消元XOR]

    题意: $5*6$网格里有一些灯告诉你一开始开关状态,按一盏灯会改变它及其上下左右的状态,问最后全熄灭需要按那些灯,保证有解 经典问题 一盏灯最多会被按一次,并且有很明显的异或性质 一个灯作为一个方程 ...

  3. POJ 1681 Painter's Problem 【高斯消元 二进制枚举】

    任意门:http://poj.org/problem?id=1681 Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total ...

  4. POJ 1681 Painter's Problem(高斯消元+枚举自由变元)

    http://poj.org/problem?id=1681 题意:有一块只有黄白颜色的n*n的板子,每次刷一块格子时,上下左右都会改变颜色,求最少刷几次可以使得全部变成黄色. 思路: 这道题目也就是 ...

  5. poj 1681 Painter&#39;s Problem(高斯消元)

    id=1681">http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. ...

  6. poj 1681 Painter's Problem

    Painter's Problem 题意:给一个n*n(1 <= n <= 15)具有初始颜色(颜色只有yellow&white两种,即01矩阵)的square染色,每次对一个方格 ...

  7. POJ 1222【异或高斯消元|二进制状态枚举】

    题目链接:[http://poj.org/problem?id=1222] 题意:Light Out,给出一个5 * 6的0,1矩阵,0表示灯熄灭,反之为灯亮.输出一种方案,使得所有的等都被熄灭. 题 ...

  8. POJ 2947 Widget Factory(高斯消元)

    Description The widget factory produces several different kinds of widgets. Each widget is carefully ...

  9. POJ 1830 开关问题(高斯消元)题解

    思路:乍一看好像和线性代数没什么关系.我们用一个数组B表示第i个位置的灯变了没有,然后假设我用u[i] = 1表示动开关i,mp[i][j] = 1表示动了i之后j也会跟着动,那么第i个开关的最终状态 ...

随机推荐

  1. mysql常用的提权方法

    一,利用MOF提权 Windows 管理规范 (WMI) 提供了以下三种方法编译到 WMI 存储库的托管对象格式 (MOF) 文件: 方法 1: 运行 MOF 文件指定为命令行参数将 Mofcomp. ...

  2. cesium编程入门(六)添加 3D Tiles,并调整位置,贴地

    添加 3D Tiles,并调整位置 3D Tiles 是什么 3DTiles数据集是cesium小组AnalyticlGraphics与2016年3月定义的一种数据集,3DTiles数据集以分块.分级 ...

  3. Spark算子--countByKey

    转载请标明出处http://www.cnblogs.com/haozhengfei/p/1633ffc63e2c925e930adadc9528c830.html  countByKey--Actio ...

  4. PHP 正则表达式匹配函数 preg_match 与 preg_match_all

    preg_match() preg_match() 函数用于进行正则表达式匹配,成功返回 1 ,否则返回 0 . 语法: 1 int preg_match( string pattern, strin ...

  5. console.log()的作用是什么

    主要是方便你调式javascript用的.你可以看到你在页面中输出的内容. 相比alert他的优点是: 他能看到结构话的东西,如果是alert,淡出一个对象就是[object object],但是co ...

  6. CGI,FAST-CGI,PHP-FPM的区别

    http://blog.csdn.net/xsgnzb/article/details/52875331 CGI全称Common Gateway Interface即公共网关接口,它遵循cgi规范,定 ...

  7. python环境搭建--pycharm的安装及使用

    学习网址: --菜鸟教程(2.0和3.0) http://www.runoob.com/python/python-tutorial.html http://www.runoob.com/python ...

  8. shopnc IM配置过程

    im配置windows下,修改chat下和data下的config,安装node,覆盖node下文件即可

  9. javascript之this

    全局作用域的this this == window //true this.a = 8 window.a 一般函数的this function thisTest(){ return this; } t ...

  10. Azure Powershell使用已有特殊化非托管磁盘创建ARM虚拟机

    生成已有特殊化非托管磁盘的方法主要有如下两种: 1.使用StorageExplorer存储管理工具,复制特殊化磁盘到一个新的容器下 2.New Portal中删除虚拟机,默认vhd文件会保留在存储账号 ...