您的位置:首页 > Web前端 > JavaScript

BZOJ1013: [JSOI2008]球形空间产生器sphere

2018-01-29 08:30 465 查看

1013: [JSOI2008]球形空间产生器sphere

Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 6490 Solved: 3365
[Submit][Status][Discuss]

Description

  有一个球形空间产生器能够在n维空间中产生一个坚硬的球体。现在,你被困在了这个n维球体中,你只知道球

面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁这个球形空间产生器。

Input

  第一行是一个整数n(1<=N=10)。接下来的n+1行,每行有n个实数,表示球面上一点的n维坐标。每一个实数精确到小数点

后6位,且其绝对值都不超过20000。

Output

  有且只有一行,依次给出球心的n维坐标(n个实数),两个实数之间用一个空格隔开。每个实数精确到小数点

后3位。数据保证有解。你的答案必须和标准输出一模一样才能够得分。

Sample Input

2

0.0 0.0

-1.0 1.0

1.0 0.0

Sample Output

0.500 1.500

HINT

  提示:给出两个定义:1、 球心:到球面上任意一点距离都相等的点。2、 距离:设两个n为空间上的点A, B

的坐标为(a1, a2, …, an), (b1, b2, …, bn),则AB的距离定义为:dist = sqrt( (a1-b1)^2 + (a2-b2)^2 +

… + (an-bn)^2 )

Source

【题解】

以第一个坐标为基准,列=r^2的式子,后面n个减去前面第一个发现次数变成1了,可以搞死小圆(PE了。。。打断了我连续一遍A的记录。。)

/**************************************************************
Problem: 1013
User: 33511595
Language: C++
Result: Accepted
Time:0 ms
Memory:1292 kb
****************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
template<class T>
inline void swap(T &a, T &b)
{
T tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}

const int INF = 0x3f3f3f3f;
const double eps = 0.00000001;

//> -1       = 0        < 1
int cmp(double a, double b)
{
if((a - b) <= eps) return 0;
return a - b < 0;
}

int n;
double a[20][20], b[20], a0[20], ai;

void gauss()
{
for(int i = 1;i <= n;++ i)
{
int p = i;
for(int j = i + 1;j <= n;++ j) if(cmp(a[p][i], a[j][i]) == 1) p = j;
for(int j = 1;j <= n;++ j) swap(a[i][j], a[p][j]); swap(b[i], b[p]);
for(int j = i + 1;j <= n;++ j)
{
if(fabs(a[j][i]) <= eps) continue;
double t = a[j][i] / a[i][i];
a[j][i] = 0;
for(int k = i + 1;k <= n;++ k) a[j][k] -= t * a[i][k]; b[j] -= t * b[i];
}
}
for(int i = n;i >= 1;-- i)
{
b[i] /= a[i][i];
for(int j = i - 1;j >= 1;-- j) b[j] -= a[j][i] * b[i];
}
}

int main()
{
read(n);
for(int j = 1;j <= n;++ j)
scanf("%lf", &a0[j]);
for(int i = 1;i <= n;++ i)
for(int j = 1;j <= n;++ j)
scanf("%lf", &ai), a[i][j] = 2 * (ai - a0[j]), b[i] += (ai - a0[j]) * (ai + a0[j]);
gauss();
for(int i = 1;i < n;++ i) printf("%.3lf ", b[i]);
printf("%.3lf", b
);
return 0;
}


BZOJ1013
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: