JSOI2008球形空間產生器

來源:互聯網
上載者:User

標籤:har   esc   點距   while   sqrt   球面   man   center   0.00   

P2182 - 【JSOI2008】球形空間產生器Description

有一個球形空間產生器能夠在n維空間中產生一個堅硬的球體。現在,你被困在了這個n維球體中,你只知道球面上n+1個點的座標,你需要以最快的速度確定這個n維球體的球心座標,以便於摧毀這個球形空間產生器。

Input

第一行是一個整數,n。
接下來的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

資料規模:

對於40%的資料,1<=n<=3

對於100%的資料,1<=n<=10

提示:給出兩個定義:

1、 球心:到球面上任意一點距離都相等的點。

2、 距離:設兩個n為空白間上的點A, B的座標為(a1, a2, …, an), (b1, b2, …, bn),則AB的距離定義為:
      dist = sqrt( (a1-b1)^2 + (a2-b2)^2 + … + (an-bn)^2 )

Source

耒陽大世界(衡陽八中) OJ 1013
解方程組

 

高斯消元裸體,通過一個座標,可以和其他n個座標建立起一個n個方程關係,在運用高斯約旦消元法即可;

 1 #include<algorithm> 2 #include<iostream> 3 #include<iomanip> 4 #include<cstring> 5 #include<cstdlib> 6 #include<cstdio> 7 #include<queue> 8 #include<ctime> 9 #include<cmath>10 #include<stack>11 #include<map>12 #include<set>13 #define rep(i,a,b) for(register int i=a;i<=b;i++)14 #define il inline15 #define ll long long16 #define db double17 using namespace std;18 #define eps 0.000000119 const int N=20;20 db a[N][N],f[N];21 int n;22 il int gi();23 void Input() {24   n=gi();25   rep(i,1,n) scanf("%lf",&f[i]);26   db t;27   rep(i,1,n)28     rep(j,1,n) {29     scanf("%lf",&t);30     a[i][j]=2*(t-f[j]);31     a[i][n+1]+=t*t-f[j]*f[j];32   }33 }34 void Gauss() {35   rep(i,1,n) {36     int line=i;37     while(line<=n&&fabs(a[line][i])<=eps) line++;// find 主元38     if(line>n) continue;39     if(line!=i)  rep(j,1,n+1) swap(a[line][j],a[i][j]) ;40     db k=a[i][i];41     rep(j,1,n+1)42       a[i][j]/=k;// 係數化為143     rep(j,1,n)//bug 1 : j hangshu  X <=n+1 X44       if(j!=i) {// bug 2:  a[j][i]<eps ? gun!45     k=a[j][i];46     rep(o,1,n+1) a[j][o]-=k*a[i][o];// Change 047       }48    }49 }50 int main() {51     freopen("HNOI.in","r",stdin);52     freopen("HNOI.out","w",stdout);53     Input();54     Gauss();55     rep(i,1,n-1) printf("%.3lf ",a[i][n+1]);56     printf("%.3lf",a[n][n+1]);57     return 0;58 }59 60 il int gi() {61     int res=0,f=1;62     char ch=getchar();63     while((ch<‘0‘||ch>‘9‘)&&ch!=‘-‘) ch=getchar();64     if(ch==‘-‘) ch=getchar(),f=-1;65     while(ch>=‘0‘&&ch<=‘9‘) res=res*10+ch-‘0‘,ch=getchar();66     return res*f;67 }

 

JSOI2008球形空間產生器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.