_bzoj1013 [JSOI2008]球形空间产生器sphere【高斯消元】
2024-08-24 00:23:30
传送门: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;
}
最新文章
- magento安装
- xcode7 打开工程错误 This Document requires xcode8.0 or later.
- html 中添加背景音乐
- php编译报错 configure: error: Please reinstall the libcurl distribution - easy.h should be in <;curl-dir>;/include/curl/
- IE和主流浏览器
- webapp调试工具weinre的使用
- 解决MVC Json序列化的循环引用问题/EF Json序列化循引用问题---Newtonsoft.Json
- 表格java代码的相关知识积累
- Java7里try-with-resources分析
- Django中的视图(view)
- vue+vue-cli+vuex+vrouter 开发学习和总结
- GNU的编译器
- ubuntu16.04安装ssh服务,并实现远程访问
- ssh端口转发(之kettle ssh方式连接数据库)
- 在Ubuntu的系统中怎样将应用程序加入到開始菜单中
- 【shell】创建长目录,目录存在则忽略,缺失则创建
- Python3 socketserver模块
- jsp的session完成登陆功能
- Ubuntu中将网卡名称eno16777736改回eth0
- 20155339《java程序设计》第一次实验报告