每个点到中心距离相等,以第0个点为参考,其他n个点到中心距等于点0到中心距,故可列n个方程

列出等式后二次未知数相消,得到线性方程组

将每个数加上1e17,求答案是再减去,求解时对一个2 * (1e17)以上的一个素数取模。

可用java 中高精度  System.out.println(BigInteger.valueOf(200000000000000001L).nextProbablePrime())  求一个大于2 * (1e17)的质数。

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std; typedef long long LL;
const LL MOD = 200000000000000003ll, M = 100000000000000000ll;
const int N = 60; //System.out.println(BigInteger.valueOf(200000000000000001L).nextProbablePrime());
LL a[N][N];
LL MultMod(LL a,LL b){
a%=MOD;
b%=MOD;
LL ret=0;
while(b){
if(b&1){
ret+=a;
if(ret>=MOD) ret-=MOD;
}
a=a<<1;
if(a>=MOD) a-=MOD;
b=b>>1;
}
return (ret % MOD + MOD) % MOD;
}
LL Ext_gcd(LL a,LL b,LL &x,LL &y){//扩展欧几里得
if(b==0) { x=1, y=0; return a; }
LL ret= Ext_gcd(b,a%b,y,x);
y-= a/b*x;
return ret;
}
LL Inv(LL a, LL m){ ///求逆元
LL d,x,y, t = m;
d= Ext_gcd(a,t,x,y);
if(d==1) return (x%t+t)%t;
return -1;
} void gauss_jordan(LL A[][N], int n){
for(int i = 0; i < n; i++){
//选择一行r与第i行交换
int r = i;
for(int j = i; j < n; j++){
if(A[j][i]){
r = j;
break;
}
}
if(r != i){
for(int j = 0; j <= n; j++){
swap(A[r][j], A[i][j]);
}
}
for(int k = i + 1; k < n; k++){
if(A[k][i]){
LL x1 = A[k][i], x2 = A[i][i];
for(int j = n; j >= i; j--){
A[k][j] = ((MultMod(A[k][j], x2) - MultMod(x1, A[i][j])) % MOD + MOD) % MOD;
}
}
}
}
for(int i = n - 1; i >= 0; i--){
for(int j = i + 1; j < n; j++){
if(A[i][j]){
A[i][n] -= MultMod(A[j][n], A[i][j]);
if(A[i][n] < 0){
A[i][n] += MOD;
}
}
}
A[i][n] = MultMod(A[i][n], Inv(A[i][i], MOD));
}
} LL x[N];
int main(){
int t;
cin>>t;
for(int cas = 1; cas <= t; cas++){
int n;
cin>>n;
for(int i = 0; i < n; i++){
cin >> x[i];
x[i] += M;
}
for(int i = 0; i < n; i++){
a[i][n] = 0;
for(int j = 0; j < n; j++){
LL t;
cin >>t;
t += M;
a[i][n] += (MultMod(t, t) - MultMod(x[j], x[j]) + MOD) % MOD;
a[i][n] %= MOD;
a[i][j] = ((2 * t - 2 * x[j]) % MOD + MOD) % MOD;
}
}
gauss_jordan(a, n);
printf("Case %d:\n", cas);
for(int i = 0; i < n - 1; i++){
printf("%I64d ", a[i][n] - M); }
printf("%I64d\n", a[n - 1][n] - M); }
return 0;
}

  

HDU3571 N-dimensional Sphere(高斯消元 同模方程)的更多相关文章

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

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

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

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

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

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

  4. HDU 3571 N-dimensional Sphere( 高斯消元+ 同余 )

    N-dimensional Sphere Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

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

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

  6. 【BZOJ 1013】【JSOI2008】球形空间产生器sphere 高斯消元基础题

    最基础的高斯消元了,然而我把j打成i连WA连跪,考场上再犯这种错误就真的得滚粗了. #include<cmath> #include<cstdio> #include<c ...

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

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

  8. BZOJ 1013 球形空间产生器sphere 高斯消元

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1013 题目大意: 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困 ...

  9. BZOJ1013球形空间产生器sphere 高斯消元

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

随机推荐

  1. bzoj 4553 && HEOI2016 day1t3 seq

    一个序列在所有变换中都单调不降的条件是i<j,a[i]<=min[j],mx[i]<=a[j],所以套CDQ就行了. #include<iostream> #includ ...

  2. input-placeholder

    :-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #f00; } ::-moz-placeholder { /* Mozilla Fir ...

  3. CSS3选择器:nth-of-type

    碰到了个选择器,:nth-of-type <!DOCTYPE html> <html> <head> <meta http-equiv="Conte ...

  4. sql语法:inner join on, left join on, right join on详细使用方法

    inner join(等值连接) 只返回两个表中联结字段相等的行 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有 ...

  5. HDU 1817Necklace of Beads(置换+Polya计数)

    Necklace of Beads Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. Solr学习总结(二)Solr的安装与配置

    接着前一篇,这里总结下Solr的安装与配置 1.准备 1.安装Java8 和 Tomcat9 ,java和tomcat 的安装这里不再重复.需要注意的是这两个的版本兼容问题.貌似java8 不支持,t ...

  7. 浅谈Android中的startActivityForResult和setResult方法

    引言 我们知道,如果想打开一个新的Activity我们可以使用startActivity方法.今天我们介绍的startActivityForResult不仅可以打开全新的Activity,而且当新的A ...

  8. AutofacContainer

    /// <summary> /// Autofac容器 /// </summary> public class AutofacContainer { public static ...

  9. java高级特性

    第二章 XML(可扩展标记语言) XML格式能够表达层次结构,并且重复的元素不会被曲解. 与HTML不同,XML是大小写敏感的. 必须有结束符. 属性值必须用引号括起来. 所有属性必须都有属性值. X ...

  10. 大熊君学习html5系列之------XHR2(XMLHttpRequest Level 2)

    一,开篇分析 Hi,大家好!大熊君又和大家见面了,(*^__^*) 嘻嘻……,这系列文章主要是学习Html5相关的知识点,以学习API知识点为入口,由浅入深的引入实例, 让大家一步一步的体会" ...