USTC OJ-1011 Problem of Deck (combinatorial mathematics, recursive relationship)

Source: Internet
Author: User

1. Title Description

According to test instructions, we can know:

Put a ruler on the edge of the table (length L), in order to keep it from falling, extend the maximum length of the desktop edge of 1/2l.

On the basis of the above, and then add a ruler, in order to keep it not falling, extend the edge of the ruler below the maximum length of 1/4l.

In addition to a ruler, in order to keep it from falling, extend the edge of the ruler below the maximum length of 1/6l.

Go down in turn ...

2. Algorithm design

By the above description, we can get a recursive relationship :

When the n ruler is accumulated, the length of the edge of the table extends

Length (0) = 0

Length (n) = Length (n-1) + 1/(2n), n≥1.

3. AC Code
1#include <stdio.h>2 #defineN 1000003 DoubleTable[n];//Table[i] I cards the length of the Extend4 5 voidPrintintn);6 7 intMain ()8 {9     intI, N; Ten     //Take table Onetable[0] =0; A      for(i =1; i < N; i++ ) -     { -Table[i] = table[i-1] +1.0/ (2*i); the     } -  -printf"# Cards overhang\n"); -      while(EOF! = scanf ("%d", &N)) +     { - print (n); +     } A } at  - voidPrintintN) - { -printf"%5d%.3lf\n", N, Table[n]); -}
View Code

USTC OJ-1011 Problem of Deck (combinatorial mathematics, recursive relationship)

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.