HDU3571 N-dimensional Sphere(高斯消元 同模方程)
每个点到中心距离相等,以第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(高斯消元 同模方程)的更多相关文章
- BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3662 Solved: 1910 [Subm ...
- BZOJ 1013: [JSOI2008]球形空间产生器sphere 高斯消元
1013: [JSOI2008]球形空间产生器sphere Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/Judg ...
- lydsy1013: [JSOI2008]球形空间产生器sphere 高斯消元
题链:http://www.lydsy.com/JudgeOnline/problem.php?id=1013 1013: [JSOI2008]球形空间产生器sphere 时间限制: 1 Sec 内 ...
- HDU 3571 N-dimensional Sphere( 高斯消元+ 同余 )
N-dimensional Sphere Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...
- 【BZOJ 1013】【JSOI2008】球形空间产生器sphere 高斯消元基础题
最基础的高斯消元了,然而我把j打成i连WA连跪,考场上再犯这种错误就真的得滚粗了. #include<cmath> #include<cstdio> #include<c ...
- HDU.3571.N-dimensional Sphere(高斯消元 模线性方程组)
题目链接 高斯消元详解 /* $Description$ 在n维空间中给定n+1个点,求一个点使得这个点到所有点的距离都为R(R不给出).点的任一坐标|xi|<=1e17. $Solution$ ...
- BZOJ 1013 球形空间产生器sphere 高斯消元
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1013 题目大意: 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困 ...
- BZOJ1013球形空间产生器sphere 高斯消元
@[高斯消元] Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球 ...
随机推荐
- Java的多线程机制系列:(一)总述及基础概念
前言 这一系列多线程的文章,一方面是个人对Java现有的多线程机制的学习和记录,另一方面是希望能给不熟悉Java多线程机制.或有一定基础但理解还不够深的读者一个比较全面的介绍,旨在使读者对Java的多 ...
- Leetcode 254. Factor Combinations
Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...
- Linux/Mac/Shell常用命令
常用命令 · ls 查看当前目录下的文件 · cd 进入某目录 · cd - 跳转回前一目录 · cd ~ 进入当前用户个人目录 · pwd 输出当前所在路径 · mkdir 新建文件夹 · touc ...
- 理解DOM
http://www.cnblogs.com/chaogex/p/3959723.html 文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言 ...
- bandicam如何录制视频
我们一般都很熟悉这类软件:屏幕录制专家和kk录制等,这些都是国内比较优秀的作品.不过exe的封装格式以及录制的清晰度让人很纠结.所以这里要为大家分享的是一款韩国人写录制软件Bandicam.Bandi ...
- foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Table' because 'System.Web.UI.WebControls.Table' does not contain a public definition for 'GetEnumerator'
错误:foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Table' because ' ...
- Charles抓Android的数据包
1. 获得Mac OS的IP地址 2. 对Android手机设置代理,主机IP是步骤1中获得的IP,端口8888
- windows7下修改hosts文件无效解决办法(转)
通常会为了开发方便.或者屏蔽掉一些恶意网站,我们会在hosts(c:\windows\system32\drivers\etc\hosts)文件中进行相应的域名指向,例:
- maven install Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project web_nanchang
maven打包成war时,报错:Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default- ...
- 适配iOS10以及Xcode8
现在在苹果的官网上,我们已经可以下载到Xcode8的GM版本了,加上9.14日凌晨,苹果就要正式推出iOS10系统的推送了,在此之际,iOS10的适配已经迫在眉睫啦,不知道Xcode8 beat版本, ...