传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1013

保存高斯消元模版。

ps,这一题的英文名字是ヨスガノソラ的开发商~^_^

#include <cstdio>
#include <cstring>
#include <cmath> const int maxn = 15; int n;
double a0[maxn], s0, t, sqr_s, geass[maxn][maxn], tem[maxn]; int main(void) {
//freopen("in.txt", "r", stdin);
scanf("%d", &n);
for (int j = 1; j <= n; ++j) {
scanf("%lf", a0 + j);
s0 += a0[j] * a0[j];
}
for (int i = 1; i <= n; ++i) {
sqr_s = 0;
for (int j = 1; j <= n; ++j) {
scanf("%lf", &t);
geass[i][j] = (t - a0[j]) * 2;
sqr_s += t * t;
}
geass[i][n + 1] = sqr_s - s0;
} int p;
double xs;
for (int i = 1; i <= n; ++i) {
p = i;
for (int j = i + 1; j <= n; ++j) {
if (fabs(geass[j][i]) > fabs(geass[p][i])) {
p = j;
}
}
if (p != i) {
memcpy(tem, geass[p], sizeof tem);
memcpy(geass[p], geass[i], sizeof tem);
memcpy(geass[i], tem, sizeof tem);
} for (int j = i + 1; j <= n; ++j) {
xs = geass[j][i] / geass[i][i];
for (int k = i; k <= n + 1; ++k) {
geass[j][k] -= geass[i][k] * xs;
}
}
} for (int i = n; i; --i) {
geass[i][n + 1] /= geass[i][i];
geass[i][i] = 1.0;
for (int j = i - 1; j; --j) {
geass[j][n + 1] -= geass[j][i] * geass[i][n + 1];
geass[j][i] = 0.0;
}
} for (int i = 1; i < n; ++i) {
printf("%.3f ", geass[i][n + 1]);
}
printf("%.3f\n", geass[n][n + 1]);
return 0;
}

  

最新文章

  1. magento安装
  2. xcode7 打开工程错误 This Document requires xcode8.0 or later.
  3. html 中添加背景音乐
  4. php编译报错 configure: error: Please reinstall the libcurl distribution - easy.h should be in &lt;curl-dir&gt;/include/curl/
  5. IE和主流浏览器
  6. webapp调试工具weinre的使用
  7. 解决MVC Json序列化的循环引用问题/EF Json序列化循引用问题---Newtonsoft.Json
  8. 表格java代码的相关知识积累
  9. Java7里try-with-resources分析
  10. Django中的视图(view)
  11. vue+vue-cli+vuex+vrouter 开发学习和总结
  12. GNU的编译器
  13. ubuntu16.04安装ssh服务,并实现远程访问
  14. ssh端口转发(之kettle ssh方式连接数据库)
  15. 在Ubuntu的系统中怎样将应用程序加入到開始菜单中
  16. 【shell】创建长目录,目录存在则忽略,缺失则创建
  17. Python3 socketserver模块
  18. jsp的session完成登陆功能
  19. Ubuntu中将网卡名称eno16777736改回eth0
  20. 20155339《java程序设计》第一次实验报告

热门文章

  1. Linux监測某一时刻对外的IP连接情况
  2. CentOS系统如何设置服务开机自动运行
  3. VC++ error C1083 无法打开包括文件 fstream.h,iostream.h怎么办
  4. leetcode ----Trie/stack专题
  5. [原创+分享]Mandelbrot Explorer
  6. Oracle 模糊查询方法
  7. NYOJ1026 阶乘末尾非0 【模板】
  8. MSMQ消息队列的安装、启用
  9. 【bzoj4320】ShangHai2006 Homework
  10. MFC项目实战(1)文件管理器--准备篇