C. Score matrix question description and solution; score matrix question Solution
Score MatrixDescription
We define the following matrix:
1/1 1/2 1/3
1/2 1/1 1/2
1/3 1/2 1/1
The elements on the diagonal line of the matrix are always 1/1, and the denominator of the scores on both sides of the diagonal line increases one by one.
The sum of the requested matrices.
Input
Given an integer N (N <50000) in each row, the matrix is N * N. When N is 0, the input ends.
Output
Output answer, retain 2 decimal places.
Sample Input
1
2
3
4
0
Sample Output
1.00
3.00
5.67
8.83
Ideas:
Matrix summation, not the summation of the determinant;
Expand the right side and bottom side to make full use of the preceding calculation results;
Code
#includeusing namespace std;
double temp=1;
double func(int n)
{
temp+=1.0/n;
return temp;
}
int main()
{
double a[50005];
a[1]=1;
for(int i=2;i<=50000;i++)
a[i]=a[i-1]+2*func(i)-1;
int n;
while(scanf("%d",&n),n){
printf("%.2f\n",a[n]);
}
return 0;
}