hdu1330 (Recursive)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1330

Analysis: Classic question,n block the same board overlap, up to reach the desktop how far

For the best pendulum of n cards, we only need to add a card with an edge to the table eaves under the pendulum of the n-1 card and move all the cards out to the eaves. For a best pendulum, its center must be on the table eaves, so must conform to the principle of leverage, the fulcrum is the table eaves. So for the case of n cards, we assume that the nth sheet moves outward x, then the center of gravity of the front n-1 is outside the table eaves X, because their center of gravity is on the table eaves when n-1 card. The center of gravity of the nth card is 0.5-x in the eaves of the table, so we can list the lever balance equation: (0.5-x) *1=x* (n-1)

Solution: x=1/(2n). Can be launched, if each plank is a unit length, then n pieces of wood can be stretched out of the table (1 + 1/2 +

1/3 + ... + 1/n)/2 units of length.

Reference: http://gd2011.teacher.com.cn/UserLog/UserLogComment.aspx?UserlogID=15319

#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineINF 1<<30#defineMoD 1000000007#defineN 100010using namespacestd;intMain () {intN; Doublea[100010]; a[1] =0.5;  for(inti =2; I <=100000; i++) A[i]= a[i-1] +1.0/i/2; printf ("# Cards overhang\n");  while(SCANF ("%d", &n) >0) {printf ("%5d%10.3lf\n", N,a[n]); }}
View Code

hdu1330 (Recursive)

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.