【BZOJ2013】【JSOI2008】球形空間產生器

來源:互聯網
上載者:User

標籤:

看chty代碼

原題:

BZOJ掛了……等好了補上題面

 

設圓心的座標為(x,y,z……),給的第一個個點的座標為(a,b,c……)

然後這個點到圓心的距離就可以表示出來:(a-x)^2+(b-y)^2+(c-z)^2+……=a^2-2ax+x^2+b^2-2by+y^2+……

然後又給了n個點,假設某個點座標為(a‘,b‘,c‘……)

兩個點到圓心的距離相等:a^2-2ax+x^2+b^2-2by+y^2+……=a‘^2-2a‘x+x^2+b‘^2-2b‘y+y^2+……

把不含未知數的都移到一邊,剩下的移到另一邊:2(a‘-a)x+2(b‘-b)y+2(c‘-c)z+……=a‘^2-a^2+b‘^2-b^2+c‘^2-c^2……

然後根據第一個點和接下來的n個點就可以構造出n個方程

然後就可以開心地用高斯消元解掉辣(然而我高斯消元的模板還沒理解+背會)

代碼:

 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 double eps=1e-6; 8 int n; 9 double b[11],a[11][11];10 void gauss(){11     int now=1;12     for(int i=1;i<=n;i++){13         int temp=now;14         while(temp<=n && !(fabs(a[temp][i])>eps))  temp++;15         if(temp>n)  continue;16         if(temp!=now)17             for(int j=1;j<=n+1;j++)18                 swap(a[temp][j],a[now][j]);19         double c=a[now][i];20         for(int j=1;j<=n+1;j++) a[now][j]/=c;21         for(int j=1;j<=n;j++)if(j!=now){22             c=a[j][i];23             for(int k=1;k<=n+1;k++)24                 a[j][k]-=c*a[now][k];25         }26         now++;27     }28 }29 int main(){30     //freopen("ddd.in","r",stdin);31     freopen("bzoj_1013.in","r",stdin);32     freopen("bzoj_1013.out","w",stdout);33     cin>>n;34     double _left;35     for(int i=1;i<=n;i++)  cin>>b[i];36     for(int i=1;i<=n;i++)37         for(int j=1;j<=n;j++){38             scanf("%lf",&_left);39             a[i][j]=2*(_left-b[j]);40             a[i][n+1]+=_left*_left-b[j]*b[j];41         }42     gauss();43     for(int i=1;i<=n;i++)  printf("%.3lf ",a[i][n+1]);44     cout<<endl;45     return 0;46 }
View Code

 

【BZOJ2013】【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.