BZOJ1013: [JSOI2008]球形空间产生器sphere
高斯消元练习。
模板:
void Guass(){
int waited;
up(i,1,N){
waited=i;
up(j,i+1,N)if(fabs(M[j][i])>fabs(M[waited][i]))waited=j;
if(waited!=i)up(j,1,N+1)swap(M[i][j],M[waited][j]);
up(k,i+1,N){
db f=M[k][i]/M[i][i];
up(j,i,N+1)M[k][j]-=f*M[i][j];
}
}
down(i,N,1){
up(j,i+1,N)M[i][N+1]-=M[j][N+1]*M[i][j];
M[i][N+1]/=M[i][i];
}
}
具体实现:
//BZOJ 1013
//by Cydiater
//2016.11.2
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <bitset>
#include <set>
#include <iomanip>
using namespace std;
#define ll long long
#define db double
#define up(i,j,n) for(int i=j;i<=n;i++)
#define down(i,j,n) for(int i=j;i>=n;i--)
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
const int MAXN=15;
const int oo=0x3f3f3f3f;
int N;
db f[MAXN],M[MAXN][MAXN];
namespace solution{
void init(){
scanf("%d",&N);
up(i,1,N)scanf("%lf",&f[i]);
up(i,1,N)up(j,1,N){
double tmp;scanf("%lf",&tmp);
M[i][j]=2*(tmp-f[j]);
M[i][N+1]+=tmp*tmp-f[j]*f[j];
}
}
void Guass(){
int waited;
up(i,1,N){
waited=i;
up(j,i+1,N)if(fabs(M[j][i])>abs(M[waited][i]))waited=j;
if(waited!=i)up(j,1,N+1)swap(M[i][j],M[waited][j]);
up(k,i+1,N){
db f=M[k][i]/M[i][i];
up(j,i,N+1)M[k][j]-=f*M[i][j];
}
}
down(i,N,1){
up(j,i+1,N)M[i][N+1]-=M[j][N+1]*M[i][j];
M[i][N+1]/=M[i][i];
}
}
void slove(){
Guass();
}
void output(){
up(i,1,N-1)printf("%.3lf ",M[i][N+1]);
printf("%.3lf\n",M[N][N+1]);
}
}
int main(){
freopen("input.in","r",stdin);
using namespace solution;
init();
slove();
output();
return 0;
}
BZOJ1013: [JSOI2008]球形空间产生器sphere的更多相关文章
- BZOJ1013 JSOI2008 球形空间产生器sphere 【高斯消元】
BZOJ1013 JSOI2008 球形空间产生器sphere Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点 ...
- BZOJ1013 [JSOI2008]球形空间产生器sphere(高斯消元)
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4846 Solved: 2525[Subm ...
- bzoj千题计划104:bzoj1013: [JSOI2008]球形空间产生器sphere
http://www.lydsy.com/JudgeOnline/problem.php?id=1013 设球心(x1,x2,x3……) 已知点的坐标为t[i][j] 那么 对于每个i满足 Σ (t[ ...
- [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...
- BZOJ1013 [JSOI2008]球形空间产生器sphere[高消]
数论进度开的好慢啊.我整天做的都是什么鬼题啊. 简单的高消题,用一个式子把另外$n$个有二次项和距离的式子全消掉就行了. #include<iostream> #include<cs ...
- 【bzoj1013】[JSOI2008]球形空间产生器sphere
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4530 Solved: 2364[Subm ...
- BZOJ 1013: [JSOI2008]球形空间产生器sphere 高斯消元
1013: [JSOI2008]球形空间产生器sphere Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/Judg ...
- 【BZOJ】1013: [JSOI2008]球形空间产生器sphere
[BZOJ]1013: [JSOI2008]球形空间产生器sphere 题意:给n+1个n维的点的坐标,要你求出一个到这n+1个点距离相等的点的坐标: 思路:高斯消元即第i个点和第i+1个点处理出一个 ...
- bzoj 1013 [JSOI2008]球形空间产生器sphere(高斯消元)
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3584 Solved: 1863[Subm ...
随机推荐
- 在SharePoint 2013 之中使用JS从Add-in程序中读取用户配置文件的属性
经过无数次的实验,只有这个程序可以运行正常 ,代码贴出来纯的JSOM,在我的实验环境老是返回未知错误,为了这一个简单的任务,我已经搞了2天了,不过终于搞出来了,使用各种方法后,还有使用代码. func ...
- [JAVA]定时任务之-Quartz使用篇
Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2SE应用程序相结合也可以单独使用.Quartz可以用来创建简单或为运行十个,百个, ...
- ALM损坏后的恢复步骤
ALM是HP出品的软件开发生命周期软件,其全称是Application Lifecycle Management,其采用B/S结构,从需求,业务模型到测试用例和缺陷管理亦应具有,满足了一般软件企业对开 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Oracle导出excel
oracle导出excel(非csv)的方法有两种,1.使用sqlplus spool,2.使用包体 现将网上相关代码整理后贴出以备不时之需: 使用sqlplus: 使用sqlplus需要两个文件: ...
- mongodb架构篇
一. 复制集 Replica set的架构 Replica set的部署 主从操作日志 在local数据库里面:db.oplog.rs.find() 日志的基本信息:db.printReplicat ...
- php类中的魔术方法
1.构造函数 析构函数class pt{ function __construct($data) { echo "pt is start ..."; $this->pr($d ...
- jdbc java数据库连接 7)获取插入数据的自增长值
我们创建一个sql表,里面的数据往往都会有自增长值. 那么,我们用jdbc插入数据的时候,要想同时获得这个增长值. 代码: /** * * 这是插入一条数据的同时,获取该数据的则增长列的值(该例子的自 ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Number of 1 Bits 位1的个数
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...