bzoj1013 [JSOI2008]球形空间产生器sphere
bzoj1013 [JSOI2008]球形空间产生器sphere
原题链接
题解
对\(k\in[2,n]\)列方程
\[\sum_{i=1}^{n}x_{i,0}(2x_{i,k}-2x_{i,k-1})=\sum_{i=1}^{n}(x_{i,k}^2-x_{i,k-1}^2)
\]
高斯消元即可。
Code
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#define Fname "bzoj_1013"
using namespace std;
#define rep(a,b,c) for(rg int a=b;a<=c;a++)
#define drep(a,b,c) for(rg int a=b;a>=c;a--)
#define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
#define db double
typedef long long ll;
il int gi(){
rg int x=0;rg char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x;
}
const int maxn=12;
db x[maxn][2];
db s[maxn][maxn];
il db sqr(db a){return a*a;}
db prt[maxn];
int main(){
//freopen(Fname".in","r",stdin);
//freopen(Fname".out","w",stdout);
int n=gi(),now=0;
rep(i,1,n)scanf("%lf",&x[i][0]);
now^=1;
rep(i,1,n){
rep(j,1,n)scanf("%lf",&x[j][now]);
db sum=0.00;
rep(j,1,n)s[i][j]=2*(x[j][now]-x[j][now^1]),sum+=sqr(x[j][now])-sqr(x[j][now^1]);
s[i][n+1]=sum;
now^=1;
}
rep(l,1,n-1)rep(i,l+1,n)drep(j,n+1,l)
s[i][j]-=s[l][j]*s[i][l]/s[l][l];
drep(i,n,1){
rep(j,i+1,n)s[i][n+1]-=s[i][j]*prt[j];
prt[i]=s[i][n+1]/s[i][i];
}
rep(i,1,n-1)printf("%.3lf ",prt[i]);
printf("%.3lf",prt[n]);
return 0;
}
博主是蒟蒻,有问题请指出,谢谢!
本博客中博文均为原创,未经博主允许请勿随意转载,谢谢。
本博客中博文均为原创,未经博主允许请勿随意转载,谢谢。