BZOJ 1013 & 高斯消元
题意:
告诉你一个K维球体球面上的K+1个点问球心坐标.
sol:
乍一看还以为是K维的二分答案然后判断距离...真是傻逼了...你看乱七八糟的题目做多了然后就会忘记最有用的基本计算...
我们可以看到,假设圆心O,根据他告诉我们的公式我们可以得到给出任意两个点和圆心的一个方程,这个方程有k个未知数,那么我们随意构造K个方程然后跑一跑高斯消元.
机械工业的线代还是挺清楚易懂的...每次枚举到一个主元行就把下面每一个都消了...恩...比较直观...
因为最后一个换行还PE了一发...有点醉= =
CODE:
/*========================================================================== # Last modified: 2016-03-03 15:29 # Filename: 1013.cpp # Description: ==========================================================================*/ #define me AcrossTheSky #include <cstdio> #include <cmath> #include <ctime> #include <string> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <set> #include <map> #include <stack> #include <queue> #include <vector> #define lowbit(x) (x)&(-x) #define FOR(i,a,b) for((i)=(a);(i)<=(b);(i)++) #define FORP(i,a,b) for(int i=(a);i<=(b);i++) #define FORM(i,a,b) for(int i=(a);i>=(b);i--) #define ls(a,b) (((a)+(b)) << 1) #define rs(a,b) (((a)+(b)) >> 1) #define getlc(a) ch[(a)][0] #define getrc(a) ch[(a)][1] #define delta 1e-6 #define maxn 100000 #define maxm 100000 #define pi 3.1415926535898 #define _e 2.718281828459 #define INF 1070000000 using namespace std; typedef long long ll; typedef unsigned long long ull; template<class T> inline void read(T& num) { bool start=false,neg=false; char c; num=0; while((c=getchar())!=EOF) { if(c=='-') start=neg=true; else if(c>='0' && c<='9') { start=true; num=num*10+c-'0'; } else if(start) break; } if(neg) num=-num; } /*==================split line==================*/ double M[20][20],p[20][20],ans[20]; int n; int judge(double x,double t){ if (fabs(x-t)<=delta) return 0; else if (x>t) return 1; return -1; } void Gauss_elimination(){ double t=1.0; FORP(i,1,n){ if (judge(M[i][i],0)!=0) t=M[i][i]; else continue; FORP(j,i,n+1) M[i][j]/=t; FORP(j,i+1,n){ t=M[j][i]; FORP(k,i,n+1) M[j][k]-=t*M[i][k]; } //check(); } FORM(i,n,1){ FORP(j,i+1,n) M[i][n+1]-=M[i][j]*ans[j]; ans[i]=M[i][n+1]; } } int main(){ read(n); FORP(i,1,n+1) FORP(j,1,n) { scanf("%lf",&p[i][j]); } FORP(i,2,n+1){ FORP(j,1,n) { M[i-1][j]=p[i][j]-p[1][j]; M[i-1][n+1]+=((p[i][j]*p[i][j]-p[1][j]*p[1][j])/2.0); } } Gauss_elimination(); FORP(i,1,n-1) printf("%.3lf ",ans[i]); printf("%.3lf",ans[n]); }
Sometimes it s the very people who no one imagines anything of. who do the things that no one can imagine.