A,B,球心坐标分别为\((a_1,a_2,a_3....),(b_1,b_2,b_3....),(c_1,c_2,c_3....)\)
则\(dist^2 = (a_1-c_1)^2+(a_2-c_2)^2+(a_3-c_3)^2\)...... \(=(b_1-c_1)^2+(b_2-c_2)^2+(b_3-c_3)^2\)......
所以\((a_1-c_1)^2+(a_2-c_2)^2+(a_3-c_3)^2\)...... \(=(b_1-c_1)^2+(b_2-c_2)^2+(b_3-c_3)^2\)......
所以\((a_1)^2-2a_1c_1-(c_1)^2+(a_2)^2-2a_2c_2-(c_2)^2\)...... \(=(b_1)^2-2b_1c_1-(c_1)^2+(b_2)^2-2b_2c_2-(c_2)^2\)......
移项得\(2c_1(a_1-b_1)+2c_2(a_2-b_2)+\)......\(=(a_1)^2-(b_1)^2+(a_2)^2-(b_2)^2\)......
式子就酱紫推出来了
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
double tem[12][12],Augmented_matrix[12][12];
inline int find_pivot( int column ) {
int maxn = column;
for (int i = column + 1; i <= n; ++i) {
if ( Augmented_matrix[i][column] < Augmented_matrix[maxn][column] ) {
maxn = i;
}
}
return maxn;
}
inline void swap_line( int now , int need ) {
for (int column = 1; column <= n + 1; ++column) {
swap( Augmented_matrix[now][column] , Augmented_matrix[need][column] );
}
return;
}
int main()
{
scanf ( "%d" , &n );
for (int i = 1; i <= n + 1; ++i) {
for (int j = 1; j <= n; ++j) {
scanf ( "%lf" , &tem[i][j] );
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
Augmented_matrix[i][j] = 2 * ( tem[i][j] - tem[i + 1][j] );
//因为保证有解 所以不可能出现一列全为0的情况
Augmented_matrix[i][n + 1] += pow( tem[i][j] , 2 ) - pow( tem[i + 1][j] , 2 );
}//化简式子后得到Augmented_martix[i][j]表示的式子
}
for (int line = 1; line <= n; ++line) {
int pivot = find_pivot( line );
swap_line( line , pivot );
for ( int tem_line = 1; tem_line <= n; ++tem_line) {
if ( tem_line != line ) {
double temp = Augmented_matrix[tem_line][line] / Augmented_matrix[line][line];
for (int column = line; column <= n + 1; ++column) {
double temp_number = Augmented_matrix[line][column] * temp;
Augmented_matrix[tem_line][column] -= temp_number;
}
}
}
}
for (int line = 1; line <= n; ++line) {
Augmented_matrix[line][n + 1] /= Augmented_matrix[line][line];
}
//正常高斯消元
for (int line = 1; line <= n; ++line) {
printf ( "%.3lf " , Augmented_matrix[line][n + 1] );
}
return 0;
}
标签:12,P4035,int,......,JSOI2008,column,产生器,2c,include
From: https://www.cnblogs.com/jueqingfeng/p/17129316.html