[Bzoj 2048] [2009 Countries Training Team] book stack "harmonic series"

Source: Internet
Author: User

Title Link: BZOJ-2048

Problem analysis

When there is only one book, the weight of the book falls on the edge of the table, and the length of the desktop is 1/2.

When there are two books, the center of gravity of the first book falls on the edge of the second book, the center of the two books on the edge of the table, the center of the two books is at the bottom of the book at the right end of 1/4. So stretch out 1/2 + 1/4.

Three books, you can stretch more than 3 of the book's center of Gravity 1/6.

The continuation of the calculation can find the law, I book The center of Gravity falls on the bottom of the book at the right end of the 1/2i.

Then the total length we ask for is sigma (1/2i) = Sigma (1/i)/2.

Sigma (1/2i) is the sum of harmonic series, if n is relatively small, we will direct O (n), because n is relatively small when the limit formula to find the error will be larger.

If n is large, we use the limit formula of the harmonic series Sigma (1/i) (i = 1 to n) = ln (n + 1) + R. R is Euler constant, r = 0.5772156649015328 ...

And then it's done.

Code
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath > #include <algorithm>using namespace std;typedef double lf;typedef long long LL; #define R 0.5772156649const LF Ep s = 1e-10; LL N, M; LF Ans;int Main () {scanf ("%lld%lld", &n, &m), if (n <= 1000000ll) {for (int i = 1; I <= n; ++i) Ans + = 1.0/(LF ) I;} else Ans = log ((LF) (n + 1)) + R; Ans/= 2.0; Ans *= (LF) m;printf ("%d\n", (int) (ans-eps)); return 0;}

  

[Bzoj 2048] [2009 Countries Training Team] book stack "harmonic series"

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.