【BZOJ 1013】球形空间产生器sphere(高斯消元)
球形空间产生器sphere HYSBZ - 1013 (高斯消元)
题意
给出n维的球上的n个点,问原球体球心。
提示
n维球体上两点距离公式\(dist = \sqrt{ (a1-b1)^2 + (a2-b2)^2 + … + (an-bn)^2 }\)
解法
\((x1-x0)^2\) --1
\((x2-x0)^2\) --2
2-1得
\((x2-x0)^2-(x1-x0)^2=0\)
-->
\(2(x2-x1)x0=(x2-x1)^2\)
类似可得
\(2(x2-x1)x0+2(y2-y1)y0+....=(x2-x1)^2+(y2-y1)^2....\)
n+1个点,可以得到n的方程,由此可以解出n个变元
参考代码一
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 40;
int equ,var;
double a[N][N];
double x[N];
double free_x[N];
double c[15][15];
int free_num;
const double eps=1e-9;
double Gauss()
{
int row,col,max_r;
int i,j;
row = col = 0;
while(row < equ && col < var)
{
max_r = row;
for(i = row+1; i < equ; i++)
if(fabs(a[i][col])-fabs(a[max_r][col]) > eps)
max_r = i;
if(max_r != row)
{
for(j = col; j <= var; j++)
swap(a[row][j],a[max_r][j]);
}
if(fabs(a[row][col]) < eps)
{
col++;
continue;
}
for(i = row+1; i < equ; i++)
{
if(fabs(a[i][col]) > eps)
{
double t = a[i][col]/a[row][col];
a[i][col] = 0.0;
for(j = col+1; j <= var; j++)
a[i][j] -= a[row][j]*t;
}
}
row++;
col++;
}
//唯一解,回代
for(int i=equ-1;i>=0;i--)
{
x[i]=a[i][var];
for(int j=i+1;j<var;j++) x[i]-=a[i][j]*x[j];
x[i]/=a[i][i];
}
return 0;
}
void init()
{
memset(a,0,sizeof(a));
memset(x,0,sizeof(x));
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<=n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%lf",&c[i][j]);
}
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<n;j++)
{
a[i-1][j]=2*(c[i][j]-c[i-1][j]);
}
a[i-1][n]=0;
for(int j=0;j<n;j++) a[i-1][n]+=(c[i][j]+c[i-1][j])*(c[i][j]-c[i-1][j]);
}
equ=n;var=n;
Gauss();
for(int i=0;i<n;i++)
{
if(i) printf(" ");
printf("%.3f",x[i]);
}
}
return 0;
}
参考代码二
/**************************************************************
Problem: 1013
User: yueguang12
Language: C++
Result: Accepted
Time:0 ms
Memory:1296 kb
****************************************************************/
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 30005
using namespace std;
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void Out(ll a){
if(a<0) putchar('-'),a=-a;
if(a>=10) Out(a/10);
putchar(a%10+'0');
}
const int N=15;
double a[N][N];
double c[15][15];
const double eps=1e-9;
int n;
bool Gauss(){
int now=1,to;double t;
for(int i=1;i<=n;i++){
for(to=now;to<=n;to++)if(fabs(a[to][i])>eps)break;
if(to>n)continue;
if(to!=now)for(int j=1;j<=n+1;j++)
swap(a[to][j],a[now][j]);
t=a[now][i];
for(int j=1;j<=n+1;j++)a[now][j]/=t;
for(int j=1;j<=n;j++) if(j!=now){
t=a[j][i];
for(int k=1;k<=n+1;k++)
a[j][k]-=t*a[now][k];
}
now++;
}
for(int i=now;i<=n;i++)
if(fabs(a[i][n+1])>eps) return 0;
return 1;
}
void Build(){
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)
{
a[i][j]=2*(c[i][j]-c[i-1][j]);
a[i][n+1]+=(c[i][j]+c[i-1][j])*(c[i][j]-c[i-1][j]);
}
}
int main(){
n=read();
for(int i=0;i<=n;i++) for(int j=1;j<=n;j++)
scanf("%lf",&c[i][j]);
Build();
Gauss();
for(int i=1;i<=n;i++){
if(i>1) printf(" ");
printf("%.3f",a[i][n+1]);
}
puts("");
return 0;
}
【BZOJ 1013】球形空间产生器sphere(高斯消元)的更多相关文章
- BZOJ 1013 球形空间产生器sphere 高斯消元
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1013 题目大意: 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困 ...
- BZOJ 1013: [JSOI2008]球形空间产生器sphere 高斯消元
1013: [JSOI2008]球形空间产生器sphere Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/Judg ...
- 【BZOJ 1013】【JSOI2008】球形空间产生器sphere 高斯消元基础题
最基础的高斯消元了,然而我把j打成i连WA连跪,考场上再犯这种错误就真的得滚粗了. #include<cmath> #include<cstdio> #include<c ...
- BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3662 Solved: 1910 [Subm ...
- lydsy1013: [JSOI2008]球形空间产生器sphere 高斯消元
题链:http://www.lydsy.com/JudgeOnline/problem.php?id=1013 1013: [JSOI2008]球形空间产生器sphere 时间限制: 1 Sec 内 ...
- [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...
- BZOJ1013球形空间产生器sphere 高斯消元
@[高斯消元] Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球 ...
- bzoj1013球形空间产生器sphere 高斯消元(有系统差的写法
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁 ...
- 【BZOJ1013】球形空间产生器(高斯消元)
[BZOJ1013]球形空间产生器(高斯消元) 题面 Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标, ...
- BZOJ_1013_[JSOI2008]_球形空间产生器_(高斯消元)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1013 n维空间,给出球上n+1个点的n维坐标,求球心坐标. 提示:给出两个定义:1. 球心:到 ...
随机推荐
- 洛谷 P1970 花匠 —— DP
题目:https://www.luogu.org/problemnew/show/P1970 普通的DP,f[i][0/1] 表示 i 处处于较小或较大的长度: 注意:1.树状数组向后 query 时 ...
- ubuntu中 python升级 (转载)
转自:http://blog.csdn.net/menglin8908/article/details/16822171 在ubuntu12.04中内置的python版本为2.7.3,最近想把pyth ...
- Codefoces 828C
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Spring 侵入式和非侵入式
1.非侵入式的技术体现 允许在应用系统中自由选择和组装Spring框架的各个功能模块,并且不强制要求应用系统的类必须从Spring框架的系统API的某个类来继承或者实现某个接口. 2.如何实现非侵入式 ...
- 超实用的jQuery代码片段
1.jQuery回到顶部效果 HTML代码:<a href="javascript:;" id="btn" title="回到顶部"& ...
- 构建一个.net的干货类库,以便于快速的开发 - 加密
在开发程序的时候,加密是一个程序一个必须的功能,基本上任何程序都会用到加密,而不同的加密方式又适应不同需求,有些加密是不可逆的,最常见是用于用户密码的加密,因为很多时候程序里面不该显示出用户的明文密码 ...
- LN : leetcode 399 Evaluate Division
lc 399 Evaluate Division 399 Evaluate Division Equations are given in the format A / B = k, where A ...
- [ CodeForces 1059 C ] Sequence Transformation
\(\\\) \(Description\) 你现在有大小为\(N\)的一个数集,数字分别为 \(1,2,3,...N\) ,进行\(N\)轮一下操作: 输出当前数集内所有数的\(GCD\) 从数集中 ...
- scroll的应用
jQuery(document).ready(function($){ $('#shang').click(function(){ $('html,body').animate({scrollTop: ...
- Angular——MVC模式开发实战
创建项目 创建工作目录 使用bower下载需要插件 git init.add.commit之后得到分支master,再创建developer分支,然后再此分支上进行具体功能开发 MVC架构 之前小项目 ...