bzoj1013题解

【解题思路】

  初看以为是二次方程组,但这些方程有相同的右值r2,于是可以化为一次方程组,高斯消元即可。复杂度O(n3)。

  化简过程:

假设第i个方程和第j个方程联立,得:

   ∑(a[i,k]-a[0,k])2=∑(a[j,k]-a[0,k])2

<=>∑(a[i,k]2+a[0,k]2-2*a[i,k]*a[0,k])=∑(a[j,k]2+a[0,k]2-2*a[j,k]*a[0,k])

<=>∑(a[i,k]2-a[j,k]2)=2*∑(a[0,k]*(a[i,k]-a[j,k]))

<=>∑(a[i,k]-a[j,k])a[0,k]=∑(a[i,k]2-a[j,k]2)/2

选取n个线性无关的区间(i,j)联立方程组(我选的是i和i+1),a[0]即是答案向量。

【参考代码】

 1 #include <iomanip>
 2 #include <iostream>
 3 #define REP(I,start,end) for(int I=start;I<=end;I++)
 4 #define PER(I,start,end) for(int I=start;I>=end;I--)
 5 #define REPs(I,start,end,step) for(int I=start;I<=end;I+=step)
 6 #define PERs(I,start,end,step) for(int I=start;I>=end;I-=step)
 7 using namespace std;
 8 template<typename T> T sqr(T n)
 9 {
10     return n*n;
11 }
12 int n;
13 long double a[20][20],A[20][20];
14 int main()
15 {
16     ios::sync_with_stdio(false);
17     cin>>n;
18     REP(i,1,n+1)
19         REP(j,1,n)
20             cin>>a[i][j];
21     REP(i,1,n)
22         REP(j,1,n)
23         {
24             A[i][j]=2*(a[i+1][j]-a[i][j]);
25             A[i][0]+=sqr(a[i+1][j])-sqr(a[i][j]);
26         }
27     REP(i,1,n-1)
28         REP(j,i+1,n)
29         {
30             long double _i=A[i][i],_j=A[j][i];
31             REP(k,0,n)
32                 A[j][k]=A[j][k]*_i/_j-A[i][k];
33         }
34     PER(i,n,1)
35         REP(j,1,i-1)
36         {
37             long double _i=A[i][i],_j=A[j][i];
38             REP(k,0,i)
39                 A[j][k]=A[j][k]*_i/_j-A[i][k];
40         }
41     REP(i,1,n-1)
42         cout<<setiosflags(ios::fixed)<<setprecision(3)<<A[i][0]/A[i][i]<<‘ ‘;
43     cout<<setiosflags(ios::fixed)<<setprecision(3)<<A[n][0]/A[n][n]<<endl;
44     return 0;
45 }
时间: 2024-08-08 13:57:40

bzoj1013题解的相关文章

BZOJ1013:[JSOI2008]球形空间产生器——题解

http://www.lydsy.com/JudgeOnline/problem.php?id=1013 Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁这个球形空间产生器. Input 第一行是一个整数n(1<=N=10).接下来的n+1行,每行有n个实数,表示球面上一点的n维坐标.每一个实数精确到小数点后6位,且其绝对值都不超过20000.

洛谷 P1079 Vigen&#232;re 密码 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:https://www.luogu.org/problem/show?pid=1079 题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简单易用,且破译难度比较高,曾在美国南北战争中为 南军所广泛使用. 在密码学中,我们称需要加密的信息为明文,用 M 表示:称加密后的信息为密文,用 C 表示:而密钥是一种

8.8联考题解

今天的T1让我怀疑我是不是在做奥赛题--这考的是什么知识点啊这个,会不会用绝对值函数? Evensgn 的债务 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Evensgn 有一群好朋友,他们经常互相借钱.假如说有三个好朋友A,B,C.A 欠 B 20 元,B 欠 C 20 元,总债务规模为 20+20=40 元.Evensgn 是个追求简约的人,他觉得这样的债务太繁杂了.他认为,上面的债务可以完全等价为 A 欠C20 元,B 既不欠别人,别人也不欠他.这样总债务规模就压缩到了 

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)

(leetcode题解)Pascal&#39;s Triangle

Pascal's Triangle  Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 题意实现一个杨辉三角. 这道题只要注意了边界条件应该很好实现出来,C++实现如下 vector<vector<int>> generate(int

2017ZZUACM省赛选拔试题部分题解----谨以纪念我这卡线滚粗的美好经历

写在前面: 其实心里有些小小的不爽又有点小小的舒畅,为啥捏?不爽当然是因为没被选拔上啦,舒畅捏则是因为没被选拔上反而让自己警醒,学长也提点很多很多."沉下去,然后一战成名"学长如是对我说,我很开心.其实这完全算不算是题解,只是我个人的一些小想法而已.而且到现在还有一题不会...让自己长点记性吧. 题目 A :聪明的田鼠 Time Limit: 1 Sec Memory Limit: 128 MB Description 田鼠MIUMIU来到了一片农田,农田可以看成是一个M*N个方格的矩

LeetCode-001题解

此题目摘自LeetCode001 Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2.

leetcode题解: Next Permutation

最近还一直在刷leetcode,当然,更多时候只是将题解写在自己的电脑上,没有分享出来.偶尔想起来的时候,就写出来. public class Solution { public void nextPermutation(int[] nums) { if(nums==null||nums.length<=1) return; nextPermutationHelp( nums,0,nums.length-1); } public void nextPermutationHelp(int []nu

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ