POJ.1681 Painter's Problem(高斯消元 异或方程组)
来源:互联网 发布:charles游戏修改数据 编辑:程序博客网 时间:2024/06/05 17:17
POJ.1681 Painter’s Problem(高斯消元 异或方程组)
标签(空格分隔): 高斯消元
题意分析
和 POJ.1222 EXTENDED LIGHTS OUT 几乎一样,区别只是规定了维数,不再是
需要注意的是,此题多了一个判断无解的情况,即无解时要输出
还有一点是,题目要求将
代码总览
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#define nmax 305using namespace std;int a[nmax][nmax];int x[nmax];int hash[nmax][nmax];int dem,ans = 0;int Gauss(int equ,int var){ int max_r,col=0,temp,k; for(k = 0;k < equ && col < var;k++,col++){ temp = max_r = k; for(int i=k+1;i<equ;i++){ if(abs(a[i][col])>abs(a[max_r][col])) max_r=i; } if(max_r!=k){ for(int j=col;j<var+1;j++) swap(a[k][j],a[max_r][j]); } if(a[k][col]==0){ k--; temp = k;continue; } for(int i=k+1;i<equ;i++){ if(a[i][col]!=0){ for(int j=col;j<var+1;j++){ a[i][j]^=a[k][j];; } } } } for(int i = k;i<equ ;++i){ if(a[i][col] != 0) return -1; } for(int i = var - 1; i >= 0; i--){ x[i]=a[i][var]; for(int j = i + 1; j < var; j++){ x[i] ^= ( a[i][j] && x[j]); } } return 0;}void init(){ int tot = 0; ans = 0; memset(x,0,sizeof x); memset(a,0,sizeof a); for(int i = 0 ;i<dem;++i) for(int j = 0;j<dem;++j) hash[i][j] = tot++; for(int i = 0;i<dem;++i){ for(int j = 0;j<dem;++j){ int t = hash[i][j]; a[t][t] = 1; if(i != 0) a[hash[i-1][j]][t] = 1; if(i != dem-1) a[hash[i+1][j]][t] = 1; if(j != 0) a[hash[i][j-1]][t] = 1; if(j != dem-1) a[hash[i][j+1]][t] = 1; } }}int main(){ //freopen("in.txt","r",stdin); int t; char ch; scanf("%d",&t); while(t--){ scanf("%d",&dem); init(); for(int i = 0;i<dem*dem;++i){ scanf(" %c",&ch); if(ch == 'y') a[i][dem*dem] = 0; else a[i][dem*dem] = 1; } if( Gauss(dem*dem,dem*dem) == -1){ printf("inf\n"); continue; } for(int i = 0;i<dem*dem;++i) if(x[i] == 1) ans++; printf("%d\n",ans); } return 0;}
阅读全文
0 0
- POJ.1681 Painter's Problem(高斯消元 异或方程组)
- 【POJ1681】Painter's Problem 高斯消元,求最小∑系数的异或方程组
- poj 1681 Painter's Problem 高斯消元
- poj 1681 Painter's Problem(高斯消元)
- poj 1681 Painter's Problem(高斯消元)
- poj 1681 Painter's Problem 高斯消元
- POJ 1681 Painter's Problem (高斯消元)
- poj 1681 Painter's Problem (高斯消元)
- poj 1681 Painter's Problem (高斯消元)
- 【高斯消元】poj 1681 Painter's Problem
- 【POJ 1681】 Painter's Problem (高斯消元)
- POJ 1681 Painter's Problem (高斯消元)
- POJ 1681 Painter's Problem(高斯消元)
- POJ 1681 Painter's Problem(高斯消元)
- poj 1681 Painter's Problem (高斯消元)
- POJ 1681 Painter's Problem(高斯消元)
- POJ 1681 Painter's Problem (高斯消元)
- poj 1681 Painter's Problem(高斯消元)
- 德州扑克 Base 1
- hive 总体架构解析
- CSS hack
- 大数阶乘
- HDU 6129 Just do it
- POJ.1681 Painter's Problem(高斯消元 异或方程组)
- 递归-N皇后
- java虚拟机内存大小设置
- HihoCoder.1196 高斯消元·二 (高斯消元 异或方程组)
- android选择图片并使用socket上传图片
- STM32 HAL库实战(一)使用STM32驱动双通道12位DAC(TLV5618)
- 股票分析软件编程开发日记与总结,自动交易软件开发
- CleanMyMac 4 免激活版 免费激活码破解 最新版下载
- Spring静态注入