这道题和之前的把那一道1222很类似。仅仅只是一定要注意一下对于无解的推断。

/*#########################################################################
# File Name: poj_1681.cpp
# Author: CaoLei
# Created Time: 2015/7/20 18:33:08
#########################################################################*/ #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define MAX(x,y) (((x)>(y))?(x):(y))
#define MIN(x,y) (((x)<(y))?(x):(y))
#define N 500010
#define pi acos(-1.0)
#define inf 100000000
typedef long long ll;
typedef unsigned long long ull;
int a[300][300];
char str[20];
int n;
bool f;
void gauss(){
for (int i = 0; i<n*n; i++){
int p=i;
for (int j = i; j<n*n; j++){ //这个地方j的初始值是i不
//是0,错了一次切记。
if (a[p][i]<a[j][i]){
p=j;
}
}
for (int j = 0; j <= n*n; j++) swap(a[i][j], a[p][j]);
int count=0;
for(int k=i;k<n*n;k++) //推断是否有解,关键
if(a[i][k]) count++;
if(!count&&a[i][n*n]){
f=false;
return ;
}
for (int j = 0; j<n*n; j++)
if (i != j&&a[j][i])
for (int k = i + 1; k <= n*n; k++)
a[j][k] ^= a[i][k]; }
} int main(){
freopen("in.txt", "r", stdin);
int t;
scanf("%d", &t);
while (t--){
f = true;
memset(a, 0, sizeof(a));
scanf("%d", &n);
for (int i = 0; i<n; i++){
scanf("%s",str);
for (int j = 0; j<n; j++){
if (str[j] == 'w'){
a[i*n + j][n*n] = 1;
}
}
}
for (int j = 0; j<n*n; j++){
a[j][j] = 1;
if (j%n != 0) a[j - 1][j] = 1;
if ((j + 1) % n != 0) a[j + 1][j] = 1;
if (j >= n) a[j - n][j] = 1;
if (j<(n - 1)*n) a[j + n][j] = 1;
}
gauss();
if (!f){
printf("inf\n");
continue;
}
int count = 0;
for (int i = 0; i<n*n; i++){
if(a[i][n*n]) count++;
}
printf("%d\n",count);
}
return 0;
}

poj_1681_高斯消元的更多相关文章

  1. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  2. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  3. *POJ 1222 高斯消元

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9612   Accepted: 62 ...

  4. [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  5. hihoCoder 1196 高斯消元·二

    Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...

  6. BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基

    [题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...

  7. SPOJ HIGH Highways ——Matrix-Tree定理 高斯消元

    [题目分析] Matrix-Tree定理+高斯消元 求矩阵行列式的值,就可以得到生成树的个数. 至于证明,可以去看Vflea King(炸树狂魔)的博客 [代码] #include <cmath ...

  8. UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  9. [高斯消元] POJ 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 614   Accepted: 286 Des ...

随机推荐

  1. 机器学习之路: python 实践 提升树 XGBoost 分类器

    git: https://github.com/linyi0604/MachineLearning 数据集被我下载到本地,可以去我的git上拿数据集 XGBoost提升分类器 属于集成学习模型 把成百 ...

  2. CodeForces 128D Numbers 构造

    D. Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  3. 指针式压力表自动读数:Auto Read the Value of Manometer

    指针式压力表的自动读数,用摄像头对准压力计,然后实时自动地读取压力计的读数.视频效果如下视频所示,红色数字为识别到的指针读数.

  4. PHP常量定义之define与const对比

    简要归纳PHP中两个常量定义关键字的区别: 1.define是函数,const是语言结构,PHP编译时const速度快.2.define只能用在类外,const类内类外皆可.3.define定义的常量 ...

  5. Google的Shell开发规范

    官方:https://google.github.io/styleguide/shell.xml 中文: http://zh-google-styleguide.readthedocs.io/en/l ...

  6. HTML5学习笔记1

    1.HTML5概述 继html4和xhtml1.0后的超文本标记语言最新版本.最重要的三项技术:html5核心规范(标签元素),CSS3,JavaScript2008年发布,主要为了补全功能.特点:1 ...

  7. Android设备运用Clockworkmod Recovery恢复模式安装定制的Rom

    Clockworkmod Recovery是一个由Cyanogen团队开发的用于Android设备的第三方定制Recovery恢复模式,也称为CWM Recovery,具体它有什么用处呢?请看关于Go ...

  8. [Erlang 0004] Centos 源代码编译 安装 Erlang

    原文地址: http://www.cnblogs.com/me-sa/archive/2011/07/09/erlang0004.html 由于最终部署的生产环境是Centos,所以我需要在Cento ...

  9. iOS 下 Podfile 使用方法

    配置 Podlist Pod 是 iOS 下包管理工具,类似于 JavaScript 里的 npm 或 yarn. 创建 Podfile 创建 Podfile 有两种方式: 打开 Terminal,在 ...

  10. 在Windows下编译Emacs

    在Windows下编译Emacs Windows下编译好的Emacs主要有两个版本,一个来自http://nqmacs.sourceforge.net/,另一个来自http://www.crasseu ...