模板特殊情况没exit(0) $\longrightarrow$60 了一下午

//#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long #define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 107;
const double eps = 1e-8; int n;
double a[N][N], ans[N];
inline double fabs(double a){
return a < 0 ? -a : a;
}
inline void Gauss(){
R(i,1,n){
int r = i;
R(j,i + 1,n)
if(fabs(a[j][i]) > fabs(a[r][i]))
r = j;
if(i != r) swap(a[i], a[r]);
if(fabs(a[i][i]) > eps){
R(j,1,n){
if(i == j) continue;
double s = a[j][i] / a[i][i];
R(k,1,n + 1)
a[j][k] -= s * a[i][k];
}
}
}
int flagNo = 0, flagInf = 0;
R(i,1,n){
int tot = 0;
R(j,1,n + 1){
if(fabs(a[i][j]) < eps)
++tot;
else
break;
}
if(tot == n + 1) flagInf = 1;
else if(tot == n && fabs(a[i][n + 1]) > eps) flagNo = 1;
}
if(flagNo == 1){ printf("-1"); exit(0);}
if(flagInf == 1){ printf("0"); exit(0);} nR(i,n,1){
ans[i] = a[i][n + 1] / a[i][i];
nR(j,i - 1,1){
a[j][n + 1] -= a[j][i] * ans[i];
}
}
} int main(){
io >> n;
R(i,1,n){
R(j,1,n + 1){
scanf("%lf", &a[i][j]);
}
} Gauss(); R(i,1,n){
// if(fabs(ans[i]) < eps)
// printf("x%d=0\n", i);
// else
printf("x%d=%.2lf\n", i, ans[i]);
} return 0;
}

最新文章

  1. jvm系列(一):java类的加载机制
  2. html和js基础功能代码备份
  3. centos7安装mplayer 错误集锦
  4. 分布式消息队列RocketMQ部署
  5. linux下多路复用模型之Select模型
  6. [IIS]在CMD中IIS的使用
  7. 关于html5不支持frameset的解决方法
  8. jQuery基本选择器
  9. 解决项目中EF5.0升级到EF6.0无法安装包的方法
  10. 自定义Operation
  11. access的时间相关的查询
  12. mongo db 使用方法
  13. JavaScript循环之for/in循环
  14. 本地phpstudy时常停机连接失败,php.ini文件中9000端口问题
  15. day 09初始函数
  16. 苹果IOS下text-shadow与box-shadow失效的解决办法
  17. Javascript 2.9
  18. Python 读、写、追加csv文件详细以及注意事项
  19. 采用PowerDesigner 设计数据库
  20. lu协程练习

热门文章

  1. CF1682C. LIS or Reverse LIS?
  2. 网易数帆 Envoy Gateway 实践之旅:坚守 6 年,峥嵘渐显
  3. (十二).NET6 + React :升级!升级!还是***升级!!!+ IdentityServer4实战
  4. Python Selenium库
  5. Mac下iTerm2安装rzsz后上传下载失败解决
  6. mysql 开启binlog日志,恢复误删的表、数据、mysql库
  7. [学习笔记]使用Docker+Jenkin自动化流水线发布.Net应用
  8. JS:null
  9. SAP Grid control( ALV Grid 列表 自定义 按钮)
  10. 给妹子讲python-S01E01好用的列表