Hdoj 2156 Fractional Matrix

Source: Internet
Author: User
Fractional matrix

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4580 Accepted Submission (s): 2769


Problem description We define the following matrices:
1/1 1/2 1/3
1/2 1/1 1/2
1/3 1/2 1/1
The element on the diagonal of the matrix is always 1/1, and the denominator of the scores on both sides of the diagonal increments.
Request the sum of this matrix.

Input is given an integer n (n<50000) per line, indicating that the matrix is n*n. When N is 0 o'clock, the input ends.

Output outputs an answer that retains 2 decimal places.

Sample Input12340

Sample Output1.003.005.678.83 Code:

#include "stdio.h" int main () {    int n;    Double sum,i;    while (scanf ("%d", &n) &&n)    {        sum=n;        i=2;        while (n--)            sum+= (1/i++) *n*2;        printf ("%.2lf\n", sum);}    }

Hdoj 2156 Fractional Matrix

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.