poj 3185 The Water Bowls (高斯消元)
来源:互联网 发布:回家吃饭网络订餐 编辑:程序博客网 时间:2024/05/21 11:26
高斯消元水过
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<queue>#include<map>#include<set>using namespace std;#define B(x) (1<<(x))void cmax(int& a,int b){ if(b>a)a=b; }void cmin(int& a,int b){ if(b<a)a=b; }typedef long long ll;const int oo=0x3f3f3f3f;const ll OO=1LL<<61;const int MOD=10007;const int maxn=444;int maze[maxn][maxn];int x[maxn],fx[maxn];int Gauss(int n,int m){ int r,c,num=0; memset(x,0,sizeof x); for(r=0,c=0;r<n&&c<m;r++,c++){ int id=r; for(int i=r+1;i<n;i++){ if(maze[i][c]>maze[id][c]){ id=i; } } if(id!=r){ for(int j=c;j<=m;j++){ swap(maze[id][j],maze[r][j]); } } if(maze[r][c]==0){ r--; fx[num++]=c; continue; } for(int i=r+1;i<n;i++){ if(maze[i][c]!=0){ for(int j=c;j<=m;j++){ maze[i][j]^=maze[r][j]; } } } } for(int i=r;i<n;i++){ if(maze[i][c]!=0)return -1; } int S=B(c-r),cnt,ans=oo; for(int s=0;s<S;s++){ cnt=0; int st=s; for(int i=0;i<c-r;i++){ x[fx[i]]=st&1; if(x[fx[i]])cnt++; st>>=1; } for(int i=r-1;i>=0;i--){ x[i]=maze[i][m]; for(int j=i+1;j<m;j++){ x[i]^=(maze[i][j]&&x[j]); } if(x[i])cnt++; } cmin(ans,cnt); } return ans;}void Init(int n){ memset(maze,0,sizeof maze); for(int i=0;i<n;i++){ maze[i][i]=1; if(i>0)maze[i-1][i]=1; if(i<n-1)maze[i+1][i]=1; }}bool input(int n){ Init(n); for(int i=0;i<n;i++){ if(scanf("%d",&maze[i][n])==EOF) return false; } return true;}int main(){//#define ON 1#ifdef ON freopen("G:\\read.txt","r",stdin);#endif // ON while(input(20)){ int ans=Gauss(20,20); printf("%d\n",ans); } return 0;}/***/
0 0
- poj 3185 The Water Bowls 高斯消元
- poj -- 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls(高斯消元)
- POJ 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls (高斯消元)
- POJ 3185 The Water Bowls(高斯消元)
- POJ 3185 The Water Bowls (高斯消元)
- poj 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls
- POJ 3185 (The Water Bowls)
- POJ 3185 The Water Bowls
- poj 3185 The Water Bowls
- POJ 3185 The Water Bowls
- POJ 3185 The Water Bowls
- POJ-3185-The Water Bowls
- poj-3185 The Water Bowls
- The Water Bowls POJ 3185
- Android学习笔记の五
- 15 Wallpaper 之OnTouch OnIntercept dispatch事件机制
- Raising Modulo Numbers (poj 1995 快速幂水题)
- c和c++的一些训练题(9)(学生成绩管理系统)
- HDU 4549 M斐波那契数列(矩阵快速幂)
- poj 3185 The Water Bowls (高斯消元)
- 怎样在Linux启动后执行指定的命令
- WindowsHOOK编程
- 黑马程序员--java基础--语言基础部分
- Web高并发解决方案
- Java的控制结构-笔记
- 无器械健身
- C++中虚析构函数的作用
- LeetCode: Fraction to Recurring Decimal