球形空间产生器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(高斯消元)的更多相关文章

  1. BZOJ 1013 球形空间产生器sphere 高斯消元

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1013 题目大意: 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困 ...

  2. BZOJ 1013: [JSOI2008]球形空间产生器sphere 高斯消元

    1013: [JSOI2008]球形空间产生器sphere Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/Judg ...

  3. 【BZOJ 1013】【JSOI2008】球形空间产生器sphere 高斯消元基础题

    最基础的高斯消元了,然而我把j打成i连WA连跪,考场上再犯这种错误就真的得滚粗了. #include<cmath> #include<cstdio> #include<c ...

  4. BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式

    1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3662 Solved: 1910 [Subm ...

  5. lydsy1013: [JSOI2008]球形空间产生器sphere 高斯消元

    题链:http://www.lydsy.com/JudgeOnline/problem.php?id=1013 1013: [JSOI2008]球形空间产生器sphere 时间限制: 1 Sec  内 ...

  6. [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  7. BZOJ1013球形空间产生器sphere 高斯消元

    @[高斯消元] Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球 ...

  8. bzoj1013球形空间产生器sphere 高斯消元(有系统差的写法

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁 ...

  9. 【BZOJ1013】球形空间产生器(高斯消元)

    [BZOJ1013]球形空间产生器(高斯消元) 题面 Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标, ...

  10. BZOJ_1013_[JSOI2008]_球形空间产生器_(高斯消元)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1013 n维空间,给出球上n+1个点的n维坐标,求球心坐标. 提示:给出两个定义:1. 球心:到 ...

随机推荐

  1. LA3704

    https://vjudge.net/problem/UVALive-3704 参考:http://www.cnblogs.com/iwtwiioi/p/3946211.html 循环矩阵... 我们 ...

  2. [Swift通天遁地]一、超级工具-(20)图片面部聚焦:使图像视图自动聚焦图片人物的面部位置

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. vim 跳行查看日志

    VIM 跳跃行号 一.显示行号 在命令模式下输入 :set nu   或者   :set number 即可显示行号 二.跳跃行号 在编辑模式下输入 ngg 或者 nG [n为指定的行数(如25)] ...

  4. 【题解】TES-Intelligence Test

    [题解]\(TES-Intelligence\) \(Test\) 逼自己每天一道模拟题 传送:\(TES-Intelligence\) \(Test\) \([POI2010]\) \([P3500 ...

  5. zabbix详细介绍及其自动动态发现

    zabbix3.2.1 第1章 安装 1.1 查看系统环境 [root@centos7-2 ~]# [root@centos7-2 ~]# hostname -I 10.0.0.10 172.16.1 ...

  6. 循环语言(for)

    循环语句: 给出初始条件,先判断是否满足循环条件,如果不满足条件则跳过for语句,如果满足则进入for语句循环,for语句内的代码执行完毕之后,将按照状态改变改变变量,然后判断是否符合循环条件,符合继 ...

  7. C#,VB.NET将PPT文档转换为HTML

    PPT文档主要用于展示,有时候我们需要将PPT文档转换为HTML格式方便查看.本文将介绍如何使用C#和VB.NET将PPT文档转换为HTML格式.该方案使用了.NET PowerPoint 组件Spi ...

  8. web开发----jsp中通用模版的引用 include的用法

    1.静态引入的示例 通过对两种用法的了解之后  我们现在 使用静态引入 因为上述原因  我的模版页中 只有div  不会有 path等定义  也不会有html标签 如下: 我的header.jsp 全 ...

  9. log4j2异步日志解读(二)AsyncLogger

    前文已经讲了log4j2的AsyncAppender的实现[log4j2异步日志解读(一)AsyncAppender],今天我们看看AsyncLogger的实现. 看了这个图,应该很清楚AsyncLo ...

  10. Java 创建Excel并逐行写入数据

    package com.xxx.common.excel; import java.io.File; import java.io.FileInputStream; import java.io.Fi ...