问题:1、列主消元为什么精度高?

2、fabs函数精确度

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; const int maxn=109;
const double eps=1e-10;
int n;
double a[maxn][maxn]; inline double douabs(double x){
if(x<0)return -x;
else return x;
} int Gauss(){
for(int j=1;j<=n;++j){
int maxline=j;
for(int i=j+1;i<=n;++i){
if(douabs(a[i][j])>douabs(a[maxline][j]))maxline=i;
}
if(maxline!=j){
for(int k=j;k<=n+1;++k)swap(a[j][k],a[maxline][k]);
}
if(douabs(a[j][j])<eps)return 0;
for(int i=j+1;i<=n;++i){
double tmp=a[i][j]/a[j][j];
for(int k=j;k<=n+1;++k){
a[i][k]=a[i][k]-tmp*a[j][k];
}
}
}
for(int i=n;i>=1;--i){
for(int j=i+1;j<=n;++j){
a[i][n+1]=a[i][n+1]-a[i][j]*a[j][n+1];
}
a[i][n+1]/=a[i][i];
}
} int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
for(int j=1;j<=n+1;++j){
scanf("%lf",&a[i][j]);
}
}
if(Gauss()==0){
printf("No Solution\n");
}else{
for(int i=1;i<=n;++i)printf("%.2f\n",a[i][n+1]);
}
return 0;
}

  

Gauss列主消元的更多相关文章

  1. HDU2449 Gauss Elimination 高斯消元 高精度 (C++ AC代码)

    原文链接https://www.cnblogs.com/zhouzhendong/p/HDU2449.html 题目传送门 - HDU2449 题意 高精度高斯消元. 输入 $n$ 个 $n$ 元方程 ...

  2. [算法] 高斯消元法 列主消元法 C++ 代码

    #include<iostream> #include<cstdio> #include<iomanip> using namespace std; #define ...

  3. poj 1681(Gauss 消元)

    Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5875   Accepted: 2825 ...

  4. 高斯消元 & 线性基【学习笔记】

    高斯消元 & 线性基 本来说不写了,但还是写点吧 [update 2017-02-18]现在发现真的有好多需要思考的地方,网上很多代码感觉都是错误的,虽然题目通过了 [update 2017- ...

  5. C# 高斯消元项目运用

    C# 高斯消元项目运用 最近项目涉及到一个需求,需要把指定数量的多个商品,混合装入到多个不同型号的箱子中(每种型号的箱子装入商品的种类和个数是固定的).这就涉及到解多元一次方程 针对多元一次方程一般用 ...

  6. POJ 1222 EXTENDED LIGHTS OUT(高斯消元解异或方程组)

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10835   Accepted: 6 ...

  7. [SDOI2010]外星千足虫(高斯消元)

    高斯消元裸题... 方法一:暴力,O(2^n)20分 方法二:直接Gauss,加点玄学技巧搞得好的话70分 方法三:使用bitset优化,复杂度:$O(\frac{n^3}{ω})$ 不会的同学看一下 ...

  8. Gauss 消元(模板)

    /* title:Gauss消元整数解/小数解整数矩阵模板 author:lhk time: 2016.9.11 没学vim的菜鸡自己手打了 */ #include<cstdio> #in ...

  9. hdu 5755(Gauss 消元) &poj 2947

    Gambler Bo Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tota ...

随机推荐

  1. 浏览器控制台报Cannot read property 'conf' of undefined

    原因:JS中有个变量没有类型导致 解决:加上类型即可(我是少写了var)

  2. ImageSwitcher和GridView的案例开发

    (一)ImageSwitcher之手机相册的滑动查看 首先在布局文件上加一个ImageSwitcher,设置它的宽度和高度为match_parent. 在主程序中:首先设置一个存储照片资源的数组,在设 ...

  3. 「ZJOI2013」K大数查询

    「ZJOI2013」K大数查询 传送门 整体二分,修改的时候用线段树代替树状数组即可. 参考代码: #include <cstdio> #define rg register #defin ...

  4. Eclipse配置maven和新建maven工程

    1 安装配置Maven 1.1 下载Maven 从Apache网站 http://maven.apache.org/ 下载并且解压缩安装Apache Maven.  Maven下载地址: http:/ ...

  5. 基于IntelliJ IDEA的代码评审插件 Code Review Plugin

    一.阿里规范公约 1.左上角 File -> Settings -> Plugins -> 搜索:Alibaba Java Coding Guidelines,安装插件并重启IDEA ...

  6. english-phoneme

    1. 声音概述 2. 音素phoneme与音标 2.1 音素与音标 2.2 音素与字母 2.3 字母发音-字母自然发音对照表 2.4 音标表 2.5 元音字母-辅音字母表 2.6 单元音发音口形趋势表 ...

  7. Linux centosVMware su命令、sudo命令、限制root远程登录

    一.su命令 Linux系统中有些事情只有root用户才能做,普通用户不能做,这时候就需要临时切换到root身份了. [root@davery ~]# whoamiroot [root@davery ...

  8. Day3-F-Buy Low Sell High-CodeForces867E

    You can perfectly predict the price of a certain stock for the next N days. You would like to profit ...

  9. C语言表结构(1)

    1.顺序表初始化实战: #include<stdio.h> #include<stdlib.h> #define OK 1 #define OVERFLOW 0 #define ...

  10. leetcode445 Add Two Numbers II

    """ You are given two non-empty linked lists representing two non-negative integers. ...