1013: [JSOI2008]球形空间产生器sphere
Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 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
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的记录。。)
1 /************************************************************** 2 ????Problem: 1013 3 ????User: 33511595 4 ????Language: C++ 5 ????Result: Accepted 6 ????Time:0 ms 7 ????Memory:1292 kb 8 ****************************************************************/ 9 ?10 #include <iostream>11 #include <cstdio>12 #include <cstring>13 #include <cstdlib>14 #include <algorithm>15 #include <queue>16 #include <vector>17 #include <map>18 #include <string> 19 #include <cmath> 20 #define min(a, b) ((a) < (b) ? (a) : (b))21 #define max(a, b) ((a) > (b) ? (a) : (b))22 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))23 template<class T>24 inline void swap(T &a, T &b)25 {26 ????T tmp = a;a = b;b = tmp;27 }28 inline void read(int &x)29 {30 ????x = 0;char ch = getchar(), c = ch;31 ????while(ch < ‘0‘ || ch > ‘9‘) c = ch, ch = getchar();32 ????while(ch <= ‘9‘ && ch >= ‘0‘) x = x * 10 + ch - ‘0‘, ch = getchar();33 ????if(c == ‘-‘) x = -x;34 }35 ?36 const int INF = 0x3f3f3f3f;37 const double eps = 0.00000001;38 ?39 ?40 //> -1 ??????= 0 ???????< 1 ?????????41 int cmp(double a, double b)42 {43 ????if((a - b) <= eps) return 0;44 ????return a - b < 0;45 }46 ?47 int n;48 double a[20][20], b[20], a0[20], ai;49 ?50 void gauss()51 {52 ????for(int i = 1;i <= n;++ i)53 ????{54 ????????int p = i;55 ????????for(int j = i + 1;j <= n;++ j) if(cmp(a[p][i], a[j][i]) == 1) p = j;56 ????????for(int j = 1;j <= n;++ j) swap(a[i][j], a[p][j]); swap(b[i], b[p]);57 ????????for(int j = i + 1;j <= n;++ j)58 ????????{59 ????????????if(fabs(a[j][i]) <= eps) continue;60 ????????????double t = a[j][i] / a[i][i];61 ????????????a[j][i] = 0;62 ????????????for(int k = i + 1;k <= n;++ k) a[j][k] -= t * a[i][k]; b[j] -= t * b[i];63 ????????}64 ????}65 ????for(int i = n;i >= 1;-- i) ??66 ????{67 ????????b[i] /= a[i][i];68 ????????for(int j = i - 1;j >= 1;-- j) b[j] -= a[j][i] * b[i];69 ????}70 }71 ?72 int main()73 {74 ????read(n);75 ????for(int j = 1;j <= n;++ j)76 ????????scanf("%lf", &a0[j]);77 ????for(int i = 1;i <= n;++ i)78 ????????for(int j = 1;j <= n;++ j)79 ????????????scanf("%lf", &ai), a[i][j] = 2 * (ai - a0[j]), b[i] += (ai - a0[j]) * (ai + a0[j]);80 ????gauss();81 ????for(int i = 1;i < n;++ i) printf("%.3lf ", b[i]);82 ????printf("%.3lf", b[n]);83 ????return 0;84 }
BZOJ1013: [JSOI2008]球形空间产生器sphere
原文地址:https://www.cnblogs.com/huibixiaoxing/p/8375756.html