pro:开关问题,同上一题。 不过只要求输出最小的操作步数,无法完成输出“inf”

sol:高斯消元的解对应的一组合法的最小操作步数。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int a[][],ans[];
int x[]={,,,,-};
int y[]={,,-,,};
bool Guass(int N)
{
rep(i,,N-){
int mark=i;
rep(j,i+,N-) if(abs(a[j][i])>abs(a[mark][i])) mark=j;
if(mark!=i) rep(j,,N) swap(a[i][j],a[mark][j]);
if(!a[i][i]) continue;
rep(j,i+,N){
if(!a[j][i]) continue;
rep(k,i,N){
a[j][k]^=a[i][k];
}
}
}
for(int i=N-;i>=;i--){
if(!a[i][i]&&a[i][N]) return false;//无解
ans[i]=a[i][N]&a[i][i];
rep(j,,i-) a[j][N]^=(a[j][i]&ans[i]);
}
return true;
}
char c[][];
int main()
{
int T,N;
scanf("%d",&T);
while(T--){
memset(a,,sizeof(a));
scanf("%d",&N);
rep(i,,N-) scanf("%s",c[i]);
rep(i,,N-)
rep(j,,N-) a[i*N+j][N*N]=(c[i][j]!='y');
rep(i,,N-)
rep(j,,N-) {
int t=i*N+j;
rep(k,,) {
if(i+x[k]>=&&i+x[k]<N&&j+y[k]>=&&j+y[k]<N){
a[(i+x[k])*N+j+y[k]][t]=;
}
}
}
if(Guass(N*N)){
int res=;
rep(i,,N*N-) res+=ans[i];
printf("%d\n",res);
}
else puts("inf");
}
return ;
}

POJ - 1681: Painter's Problem (开关问题-高斯消元)的更多相关文章

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

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

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

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

  3. poj 1681 Painter's Problem

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

  4. POJ 3185 The Water Bowls 【一维开关问题 高斯消元】

    任意门:http://poj.org/problem?id=3185 The Water Bowls Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  5. POJ 1830 开关问题 高斯消元,自由变量个数

    http://poj.org/problem?id=1830 如果开关s1操作一次,则会有s1(记住自己也会变).和s1连接的开关都会做一次操作. 那么设矩阵a[i][j]表示按下了开关j,开关i会被 ...

  6. POJ - 1222: EXTENDED LIGHTS OUT (开关问题-高斯消元)

    pro:给定5*6的灯的状态,如果我们按下一个灯的开关,它和周围4个都会改变状态.求一种合法状态,使得终状态全为关闭: sol:模2意义下的高斯消元. 终于自己手打了一个初级板子. #include& ...

  7. POJ 1166 The Clocks (爆搜 || 高斯消元)

    题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...

  8. Problem A: Apple(高斯消元)

    可以发现具有非常多的方程, 然后高斯消元就能85分 然而我们发现这些方程组成了一些环, 我们仅仅设出一部分变量即可获得N个方程, 就可以A了 trick 合并方程 #include <cstdi ...

  9. 【POJ】1222 EXTENDED LIGHTS OUT(高斯消元)

    http://poj.org/problem?id=1222 竟然我理解了两天..... 首先先来了解异或方程组(或者说mod2方程组,modk的话貌似可以这样拓展出来) 对于一些我们需要求出的变量a ...

随机推荐

  1. Ubuntu安装tomcat

    1.下载需要的tomcat二进制包(tar.gz)结尾的. https://tomcat.apache.org/download-80.cgi 2.通过xftp5 上传到指定的文件夹 3.cd进指定文 ...

  2. TF-IDF特征选择

  3. SGD、GD

    GD参考: https://blog.csdn.net/CharlieLincy/article/details/70767791 SGD参考:https://blog.csdn.net/Charli ...

  4. python(元组,不可修改序列)

    元组也是序列,区别于列表,它不可更改,语法简单只要加逗号隔开即可 1.1,2,3 (1,2,3) 2.42, (42,) 3.3*(40+2) 126 3*(40+2,) (42,42,42) 4.x ...

  5. balcanced-binary-tree

    题目描述 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bi ...

  6. python 统计单词个数,并按个数与字母排序

    # coding: utf-8 # In[1]: import collections str = "Be slow to promise and quick to perform" ...

  7. egret 简单的四方向的a星寻路,在wing中可以直接跑

    /** * main类中加载场景 * 创建游戏场景 * Create a game scene */ private createGameScene() { MtwGame.Instance.init ...

  8. JDBC连接ORACLE的三种URL格式

    格式一: Oracle JDBC Thin using an SID jdbc:oracle:thin:@host:port:SID 例如: jdbc:oracle:thin:@localhost:1 ...

  9. linux 普通用户授权root相关权限

    先查看当前用户(test)是否有特权 [test@web01 ~]$ sudo -l We trust you have received the usual lecture from the loc ...

  10. 介绍一下Spring Cloud简介

    Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智能路由,微代理,控制总线).分布式系统的协调导致了样板模式, 使用Spring Clo ...