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维球体的球 ...
随机推荐
- NSArray 倒序 输出
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"1",@"2",@"3" ...
- iOS音乐播放器相关
iOS音乐播放器框架主要有两大类:AvPlayer.AvaudioPlayer AvPlayer 能播放本地及网络歌曲 AvaudioPlayer 能播放本地歌曲.有相关代理方法(其实也可以播放网络歌 ...
- Nginx简易配置文件(一)(静态页面及PHP页面解析)
user nobody nobody; worker_processes 4; error_log logs/error.log; pid logs/nginx.pid; events { use e ...
- 框架集(Framesets)
1.Frameset的使用 所谓框架便是网页画面分成几个框窗,同时取得多个 URL.只 要 <FRAMESET> <FRAME> 即可,而所有框架标记 要放在一个总起的 htm ...
- 【CityHunter】通过Unity3D来制作游戏中AR部分的内容
嗯,最近再考虑,CityHunter中,玩家攻略藏宝图时,为了增加可玩性,应该增强在AR部分的游戏性.最近特别火的游戏<Pokemon Go>在打开摄像头以后,可以看到小精灵,实际上,如果 ...
- JQuery中$.ajax()方法参数详解(转载)
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- Dapper.Net 应用
Dapper应用 1.Dapper是什么 Dapper是一款轻量级ORM工具.如果你在小的项目中,使用Entity Framework.NHibernate 来处理大数据访问及关系映射,未免有点杀鸡用 ...
- Spring BeanNameAutoProxyCreator 与 ProxyFactoryBean区别
一般我们可以使用ProxyBeanFactory,并配置proxyInterfaces,target和interceptorNames实现,但如果需要代理的bean很多,无疑会对spring配置文件的 ...
- Asp.Net HttpContext.RemapHandler 用法
最近在看HttpHandler映射过程文章时发现Context对象中有一个RemapHandler方法,它能将当前请求映射到指定的HttpHandler处理,可跳过系统默认的Httphandler.它 ...
- [nosql之redis]yum安装redis
1.首先对于这种nosql来说目前我用到的功能很少,所以感觉没有必要去优化他跟不需要去编译安装.今天来介绍下一个yum安装redis 步骤1:安装扩展yum库 [root@localhost ~]# ...