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维球体的球 ...
随机推荐
- Android中Shape的使用
先看一下文档对Shape Drawable的描述: Shape Drawable An XML file that defines a geometric shape, including color ...
- VS 团队资源管理 强制解锁锁定文件
故事是这样发生的: 以前有台电脑,在团队资源里看程序,可能冥冥中不小心按了个空格,so,文件被锁定 而我却没有发现 如果再给我一个机会,我只想说记得签入 然后,高潮来了 重装电脑 欣喜的装好新机子打开 ...
- Map工具系列-06-销售营改增历史数据处理工具
所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...
- loadrunner关联取参--响应值unicode编码处理过
背景:做电商提交订单,需要获取订单号,然后进行支付.状态变更等操作 submitOrder() { lr_think_time(); /* 提交订单 */ /* specsId:规格ID,hyh_go ...
- SDK 支付
充值:用什么买什么 MSDK: Q点:百科 http://baike.baidu.com/link?url=Dw8ySUIvv6AAprULG_wnI7Mst61gG4bO2qzfpfi1j9xx6c ...
- Android 签名证书
Android APK的数字签名的作用和意义 http://blog.csdn.net/gaomatrix/article/details/6568191 http://jingyan.baidu.c ...
- 四、Shell输入、输出功能和字符颜色设置
一.Shell输入功能 1.键盘输入 方式一: [root@Salve four]# cat test.sh #!/bin/bash #-e 参数可以解析语句中的转义字符 echo -e &quo ...
- memcached的key,value,过期时间的限制
1. key值最大长度? memcached的key的最大长度是250个字符,是memcached服务端的限制. 如果您使用的客户端支持"key的前缀"或类似特性,那么key( ...
- Top 15 Java Utility Classes
In Java, a utility class is a class that defines a set of methods that perform common functions. Thi ...
- 以空白符结尾的 alias
网上经常有人问这个问题:为什么我写的 alias 在 sudo 下就不管用了? $ alias 'll=ls -l' $ sudo ll a-private-dir sudo: ll: command ...