高斯消元异或版模板
来源:互联网 发布:楼凤阁 源码 编辑:程序博客网 时间:2024/06/02 02:24
/**2016 - 09 - 08 晚上Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 400;const int MOD = 1e9+7;const double eps = 1e-7;const double PI = acos(-1);using namespace std;LL Scan_LL()///输入外挂{ LL res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res;}int Scan_Int()///输入外挂{ int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res;}void Out(LL a)///输出外挂{ if(a>9) Out(a/10); putchar(a%10+'0');}int equ, var;///equ个方程 var个变量int a[MAXN][MAXN];///增广矩阵int x[MAXN];///解集int x_i[MAXN];bool free_x[MAXN];///判断是不是自由变元int free_num;///自由变元的个数int Gauss(){ int Max_r;///当前列绝对值最大的存在的行 ///col:处理当前的列 int row,col = 0; int free_x_num; int free_index; free_num = 0; for(int i=0; i<=var; i++) { x[i] = 0; free_x[i] = 1; } for(row=0; row<equ&&col<var; row++,col++) { Max_r = row; for(int i=row+1; i<equ; i++) if(abs(a[i][col]) > abs(a[Max_r][col])) Max_r = i; if(a[Max_r][col] == 0) { free_x[col] = 1; x_i[free_num++] = col; row--; continue; } if(Max_r != row) for(int i=col; i<var+1; i++) swap(a[row][i], a[Max_r][i]); ///消元 for(int i=row+1; i<equ; i++) if(a[i][col]) for(int j=col; j<var+1; j++) a[i][j] ^= a[row][j]; } for(int i=row; i<equ; i++) if(a[i][col]) return -1;///无解 ///保证对角线主元非 0 for(int i=0; i<equ; i++) { if(!a[i][i]) { int j; for(j=i+1; j<var; j++) if(a[i][j]) break; if(j == var) break; for(int k=0; k<equ; k++) swap(a[k][i], a[k][j]); } } if(row < var) return var - row;///自由变元的个数 ///回代,得到解集 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 Debug(){ puts(""); cout<<"+++++++++++++++++++++++++++分界线++++++++++++++++++++++++++++++"<<endl; for(int i=0; i<equ; i++) { for(int j=0; j<var+1; j++) { cout<<a[i][j]<<" "; } cout<<endl; } cout<<"+++++++++++++++++++++++++++分界线++++++++++++++++++++++++++++++"<<endl; puts("");}int main(){ while(cin>>equ>>var) { for(int i=0; i<equ; i++) { for(int j=0; j<var+1; j++) cin>>a[i][j]; } ///Debug(); cout<<Gauss()<<endl; } return 0;}
0 0
- 高斯消元异或版模板
- 高斯消元法解异或方程组 模板
- 高斯消元解异或方程组 模板
- 等差数列连续异或模板
- eclipse或myeclipse模板设置
- [模板]高斯消元,异或方程组
- poj3461 KMP模板 或 哈希
- seo之前网站源码或模板选择
- 高斯消元模板(+解异或方程组)
- Spring中使用FreeMaker或Vilocity模板发送邮件
- Spring中使用FreeMaker或Vilocity模板发送邮件
- SDI或MDI中获得某个文档模板的视图
- Spring中使用FreeMaker或Vilocity模板发送邮件
- 使用smarty模板或缓存实现页面静态化
- WordPress常用模板函数 修改或自制WordPress主题必备
- T4模板中获取当前项目或解决方案路径
- cf244D. Match & Catch 字符串hash (模板)或 后缀数组。。。
- (C++)用模板或宏实现单例模式
- 函数指针应用总结(未完成)
- NEFU 1191 BFS
- 51nod--1183 编辑距离
- (二)OpenGL中的Shader
- [转]Spring事务管理(详解+实例)
- 高斯消元异或版模板
- OkHttp与Retrofit上传文件详解
- 教你如何使用IDEA新建WEB工程
- 中后求前
- LeetCode-Palindrome Numbers
- U-BOOT-2016.07移植 (第三篇) 代码重定位
- AlertDialog.Builder和AlertDialog之间的关系
- 14 Fragment 碎片总结
- 《机器学习实战》预测数值型数据-回归(Regression)