当前位置:网站首页>PAT B1063

PAT B1063

2022-06-25 19:57:00 Madness makes freedom

1063 Calculate the spectral radius (20 branch )

In mathematics , Matrix “ Spectral radius ” Is the supremum of the modular set of its eigenvalues . In other words , For a given n Eigenvalues of a complex space { a1​+b1​i,⋯,an​+bn​i }, Their modules are the square of the sum of squares of real and imaginary parts , and “ Spectral radius ” Is the maximum module .

Now let's give some eigenvalues of complex space , Please calculate and output the spectral radius of these eigenvalues .

Input format :

Enter the first line to give a positive integer N(≤ 10 000) Is the number of input eigenvalues . And then N That's ok , Each line gives 1 The real and imaginary parts of eigenvalues , Separated by spaces . Be careful : The problem is to ensure that both the real part and the imaginary part are absolute values that do not exceed 1000 The integer of .

Output format :

Output the spectral radius in one line , Round to decimal 2 position .

sample input :

5
0 1
2 0
-1 0
3 3
0 -3

sample output :

4.24

The topic is clearly understood , It should be done by lifting the key , But unfortunately , The definition of spectral radius is not clear to me . It's hard !!

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n,a,b,sum_squ=0;
    cin >> n;
    while(n--)
    {
        cin >> a >> b;
        sum_squ=max(sum_squ,a*a+b*b);
    }
    double sqr=sqrt(sum_squ*1.0);
    printf("%.2f\n",sqr);
    return 0;

}

原网站

版权声明
本文为[Madness makes freedom]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190512259639.html