在數(shù)學(xué)中,矩陣的“譜半徑”是指其特征值的模集合的上確界。換言之,對(duì)于給定的n個(gè)復(fù)數(shù)空間的特征值{a1+b1i, …, an+bni},它們的模為實(shí)部與虛部的平方和的開方,而“譜半徑”就是最大模。
現(xiàn)在給定一些復(fù)數(shù)空間的特征值,請(qǐng)你計(jì)算并輸出這些特征值的譜半徑。
輸入格式:
輸入第一行給出正整數(shù)N(<= 10000)是輸入的特征值的個(gè)數(shù)。隨后N行,每行給出1個(gè)特征值的實(shí)部和虛部,其間以空格分隔。注意:題目保證實(shí)部和虛部均為絕對(duì)值不超過1000的整數(shù)。
輸出格式:
在一行中輸出譜半徑,四舍五入保留小數(shù)點(diǎn)后2位。
輸入樣例: 5 0 1 2 0 -1 0 3 3 0 -3 輸出樣例: 4.24
#include <iostream>#include <cmath> #include <cstdio> using namespace std;int main(){ int N; cin>>N; double R[N]; double max = 0; for ( int i = 0 ; i < N ; i++){ int imaginary,real; cin>>real>>imaginary; R[i] = sqrt(real*real+imaginary*imaginary); if ( max < R[i]){ max = R[i]; } }新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注