N-dimensional Sphere

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 668    Accepted Submission(s): 234

Problem Description
In an N-dimensional space, a sphere is defined as {(x1, x2 ... xN)| ∑(xi-Xi)^2 = R^2 (i=1,2,...,N) }. where (X1,X2…XN) is the center. You're given N + 1 points on an N-dimensional sphere and are asked to calculate the center of the sphere.
 
Input
The first line contains an integer T which is the number of test cases.
For each case there's one integer N on the first line.
Each of the N+1 following lines contains N integers x1, x2 ... xN describing the coordinate of a point on the N-dimensional sphere.
(0 <= T <= 10, 1 <= N <= 50, |xi| <= 10^17)
 
Output
For the kth case, first output a line contains “Case k:”, then output N integers on a line indicating the center of the N-dimensional sphere
(It's guaranteed that all coordinate components of the answer are integers and there is only one solution and |Xi| <= 10^17)
 
Sample Input
2
2
1 0
-1 0
0 1
3
2 2 3
0 2 3
1 3 3
1 2 4
 
Sample Output
Case 1:
0 0
Case 2:
1 2 3
 
 
 
这条题目的做法很容易想出来 。
凭借 n + 1 个点代入 n 维圆公式, 求圆心 。
然后用第 n + 1 个方程( 设下标为n )  sigma( ( Xi - Oi )^2 )  = R^2 
跟前n 个方程联立容易得到 :
  sigma( ( Xi - Oi )^2 )  =  sigma( ( Yi - Oi )^2 )  
两边都展开然后消掉Oi^2就得到
  sigma(  2*( Xi - Yi )*Oi ) = sigma(  Xi^2 - Yi^2 )  .
得到 n 个这样的 n 元一次方程之后就可以利用高斯消元解决。
 
但首先 fabs( xi ) <= 1e17 的。 大数据的话显然计算过程溢出 。
就用到  sigma( ai * xi ) = an ( % mod ) 来解决。 求得解依然唯一。
 
在高斯消元的过程中会有除法 , 用求逆来解决。
由于数据很大, 欧拉定理会溢 , 那么用扩展欧几里得就OK 。
 
然后还需要将数据加一个偏移差,把所有数据处理成正数 (相当于把整个图形平移了,最后减回来不影响结果)。
避免在取余过程中把(负数+mod)%mod弄成了正。
 
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lr rt<<1
#define rr rt<<1|1
typedef long long LL;
typedef pair<int,int>pii;
#define X first
#define Y second
const int oo = 1e9+;
const double PI = acos(-1.0);
const double eps = 1e- ;
const int N = ;
#define mod 200000000000000003LL
#define dif 100000000000000000LL LL Mod(LL x) {
if (x >= mod) return x - mod;
return x;
}
LL mul(LL a, LL b) {
LL res;
for (res = ; b; b >>= ) {
if (b & )
res = Mod(res + a);
a = Mod(a + a);
}
return res;
} void e_gcd( LL a , LL b , LL &d , LL &x , LL &y ) {
if( !b ){ d = a , x = , y = ; return ; }
e_gcd( b , a%b , d , y , x );
y -= x*(a/b);
} LL inv( LL a , LL n ){
LL d,x,y ;
e_gcd(a,n,d,x,y);
return ( x % n + n ) % n ;
} LL A[N][N] , g[N][N];
int n ; void Gauss() { for( int i = ; i < n ; ++i ) {
int r = i ;
for( int j = i ; j < n ; ++j ) {
if( g[j][i] ) { r = j ; break ; }
}
if( r != i ) for( int j = ; j <= n ; ++j ) swap( g[i][j] , g[r][j] ) ; LL INV = inv( g[i][i] , mod );
for( int k = i + ; k < n ; ++k ) {
if( g[k][i] ) {
LL f = mul( g[k][i] , INV );
for( int j = i ; j <= n ; ++j ) {
g[k][j] -= mul( f , g[i][j] );
g[k][j] = ( g[k][j] % mod + mod ) % mod ;
}
}
}
}
for( int i = n - ; i >= ; --i ){
for( int j = i + ; j < n ; ++j ){
g[i][n] -= mul( g[j][n] , g[i][j] ) , g[i][n] += mod , g[i][n] %= mod ;
}
g[i][n] = mul( g[i][n] , inv( g[i][i] , mod ) );
}
} void Run() { scanf("%d",&n);
memset( g , , sizeof g );
for( int i = ; i <= n ; ++i ) {
for( int j = ; j < n ; ++j ) {
scanf("%I64d",&A[i][j]);
A[i][j] += dif ;
}
} for( int i = ; i < n ; ++i ){
for( int j = ; j < n ; ++j ){
g[i][j] = Mod( A[n][j] - A[i][j] + mod );
g[i][j] = mul( g[i][j] , ) ;
g[i][n] = Mod( g[i][n] + mul( A[n][j] , A[n][j] ) );
g[i][n] = Mod( g[i][n] - mul( A[i][j] , A[i][j] ) + mod );
}
} Gauss();
printf("%I64d",g[][n]-dif);
for( int i = ; i < n ; ++i ){
printf(" %I64d",g[i][n]-dif);
}puts("");
} int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int cas = , _ ; scanf("%d",&_ );
while( _-- ){
printf("Case %d:\n",cas++); Run();
}
}

HDU 3571 N-dimensional Sphere( 高斯消元+ 同余 )的更多相关文章

  1. HDU.3571.N-dimensional Sphere(高斯消元 模线性方程组)

    题目链接 高斯消元详解 /* $Description$ 在n维空间中给定n+1个点,求一个点使得这个点到所有点的距离都为R(R不给出).点的任一坐标|xi|<=1e17. $Solution$ ...

  2. BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式

    1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3662 Solved: 1910 [Subm ...

  3. BZOJ 1013: [JSOI2008]球形空间产生器sphere 高斯消元

    1013: [JSOI2008]球形空间产生器sphere Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/Judg ...

  4. HDU 5755 Gambler Bo(高斯消元)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5755 [题目大意] 一个n*m由0,1,2组成的矩阵,每次操作可以选取一个方格,使得它加上2之后对 ...

  5. HDU 4818 RP problem (高斯消元, 2013年长春区域赛F题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4818 深深地补一个坑~~~ 现场赛坑在这题了,TAT.... 今天把代码改了下,过掉了,TAT 很明显 ...

  6. ACM学习历程—HDU 3949 XOR(xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...

  7. lydsy1013: [JSOI2008]球形空间产生器sphere 高斯消元

    题链:http://www.lydsy.com/JudgeOnline/problem.php?id=1013 1013: [JSOI2008]球形空间产生器sphere 时间限制: 1 Sec  内 ...

  8. [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  9. hdu 5833 Zhu and 772002 高斯消元

    Zhu and 772002 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test ...

随机推荐

  1. Javascript中中括号的几种形式

    有以下几种形式 var arr = []; var b = [1,1,1]; var c = b[0]; var obj = {'name':'tom','age':23}; var d = obj[ ...

  2. Java JNA (二)—— dll回调函数实现

    java调用dll文件需要使用回调函数作为公开函数的参数时,用以下方法实现: 首先,看c++中定义的dll公开函数: typedef void (*ccback)(char *name ,int le ...

  3. 第十五章 Kubernetes调度器

    一.简介 Scheduler 是 kubernetes 的调度器,主要的任务是把定义的 pod 分配到集群的节点上.听起来非常简单,但有很多要考虑的问题: ① 公平:如何保证每个节点都能被分配资源 ② ...

  4. java String练习题

    package java07; /* 题目: 定义一个方法,把数组{1,2,3}按照指定格式拼接成一个字符串,格式参照如下:[word1#word2#word3] 思路: 1.首先准备一个int[]数 ...

  5. Mybatis-Generator demo

    使用Mybatis-Generator自动生成Dao.Model.Mapping相关文件(转) https://www.cnblogs.com/smileberry/p/4145872.html == ...

  6. maven clean后 编译报错

    <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <config ...

  7. Tomcat 9 安装

    1.下载 官网:https://tomcat.apache.org/ 在浏览器地址栏输入地址,进入下图页面. 点击下图红色标记处(笔者选择的Tomcat 9下载,读者可根据需要自行选择) 下图蓝色标记 ...

  8. mysql,分组后,再次进行过滤

    查出平均分大于80以上的班级 select class_id, avg(score) from students group by class_id having avg(score)>80;  ...

  9. nyoj 762:第k个互质数

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=762 直接给代码好了,容斥原理具体看<组合数学> #include<bi ...

  10. React笔记02——React中的组件

    一个网页可以被拆分成若干小部分,每个部分都可以称为组件,即组件是网页中的一部分.组件中还可以有多个组件. 上一节中的App.js就是一个组件(继承了React.Component类的类). 一个组件的 ...