C. Score matrix question description and solution; score matrix question Solution

Source: Internet
Author: User

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;
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.