码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 高斯消元


    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef pair<int, int> PII;
    6. typedef long long ll;
    7. typedef long double ld;
    8. const int N = 110;
    9. const double eps = 1e-6;
    10. int n;
    11. double a[N][N];
    12. int gauss()
    13. {
    14. int r, c;//行 列
    15. for(c = 0, r = 0; c < n; c ++)
    16. {
    17. int t = r;
    18. for(int i = r + 1; i < n; i ++)
    19. {//找到最大的行
    20. if(fabs(a[i][c]) > fabs(a[t][c]))
    21. {
    22. t = i;
    23. }
    24. }
    25. if(abs(a[t][c]) < eps)continue;
    26. for(int j = c; j <= n; j ++)
    27. {//与最大行交换
    28. swap(a[t][j], a[r][j]);
    29. }
    30. //第一个数变为1
    31. for(int j = n; j >= c; j --)a[r][j] /= a[r][c];
    32. for(int i = r + 1; i < n; i ++)
    33. {
    34. for(int j = n; j >= c; j --)
    35. {
    36. a[i][j] -= a[i][c] * a[r][j];
    37. }
    38. }
    39. r ++;
    40. }
    41. if(r < n)
    42. {
    43. for(int i = r; i < n; i ++)
    44. if(abs(a[i][n]) > eps)
    45. return 2;
    46. return 1;
    47. }
    48. for(int i = n - 1; i >= 0; i --)
    49. {
    50. for(int j = i + 1; j < n; j ++)
    51. {
    52. a[i][n] -= a[j][n] * a[i][j];
    53. }
    54. }
    55. return 0;
    56. }
    57. int main()
    58. {
    59. scanf("%d", &n);
    60. for(int i = 0; i < n; i ++)
    61. for(int j = 0; j <= n; j ++)
    62. scanf("%lf", &a[i][j]);
    63. int t = gauss();
    64. if(t == 0)
    65. {
    66. for(int i = 0; i < n; i ++)
    67. {
    68. if(fabs(a[i][n]) < eps)a[i][n] = 0;//防止出现-0.00
    69. printf("%.2lf\n", a[i][n]);
    70. }
    71. }
    72. else if(t == 1)printf("Infinite group solutions\n");
    73. else printf("No solution\n");
    74. return 0;
    75. }

  • 相关阅读:
    Fabric.js 图形标注
    react create-react-app v5配置 px2rem (暴露 eject方式)
    C++学习第八课--迭代器精彩演绎、失效分析及弥补、实战笔记
    中科驭数DPU芯片K2斩获2023年“中国芯”优秀技术创新产品奖
    Kernel: 宏:__KERNEL__
    css继承属性
    【前端灵魂脚本语言JavaScript⑤】——JS中数组的使用
    广西师范大学计算机考研资料汇总
    数据仓库项目从来不是技术项目
    一篇文章熟练掌握Git
  • 原文地址:https://blog.csdn.net/a1695574118/article/details/133211309
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号