Hangzhou Electric HDU ACM 1330 Deck

Source: Internet
Author: User

Deck Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1299 Accepted Submission (s): 749


Problem Descriptiona single Playing card can is placed on a table, carefully, so, and the short edges of the card is para Llel to the table's edge, and half the length of the the card hangs over the edge of the table. If the card hung any further out, with its center of gravity off the table, it would fall off the table and flutter to the Floor. The same reasoning applies if the card were placed on another card, and rather than on a table.

Playing cards can is arranged, carefully, with short edges parallel to table edges, to extend 3/4 of a card length Bey Ond the edge of the table. The top card hangs half a card length past the edge of the the bottom card. The bottom card hangs with a only quarter of its length past the table ' s edge. The center of gravity of the cards combined lies just over the edge of the table.

Three playing cards can be arranged, with short edges parallel to table edges, and all card touching at the most one other CA Rd, to extend 11/12 of a card length beyond the edge of the table. The top of the cards extend 3/4 of a card length beyond the edge of the bottom card, and the bottom card extends only 1/6 ove R the table ' s edge; The center of gravity of the three cards lines over the edges of the table.

If you keep stacking cards so, the edges is aligned and every card have at most one card above it and one below it, ho W far off can 4 cards extend over the table ' s edge? Or cards? Or cards? Or 99999?

Inputinput contains several nonnegative integers, one to a line. No integer exceeds 99999.

Outputthe standard output would contain, on successful completion of the program, a heading:

# Cards Overhang

(That's spaces between the words) and, following, a line for each input integer giving the length of the longest overh Ang achievable with the given number of cards, measured in cardlengths, and rounded to the nearest thousandth. The length must is expressed with at least one digit before the decimal point and exactly three digits after it. The number of cards is right-justified in column 5, and the decimal points for the lengths lie in column 12.

Sample Input

Sample Output
The line of digits are intended to guide you in proper output alignment, and are not part of the output that your solution s Hould Produce. 12345678901234567# Cards  Overhang    1     0.500    2     0.750    3     0.917    4     1.042   30     1.997

Sourcesouth Central USA 1998

This problem is a physics problem, no idea, search the physical solution: if the high school physics background is not good, the following words can not understand.

This is a very classic question. The traditional answer is to put the center of gravity of the first plank on the right edge of the second plank, put the center of gravity of the two planks on the right edge of the third plank, and place the center of gravity of the three planks on the right edge of the fourth plank. Using the lever principle can be introduced, if each plank is the unit length, then the n block can extend the desktop (1 + + 1/3 + ... + 1/n)/2 units length. By the nature of the harmonic series, we can immediately be informed that, as long as the number of boards is enough, the length of the wood sticks out of the table is no upper bound, want to stretch out how long can reach out to how long. But at the same time, this growth rate is also very slow?? 20 planks can only stretch out about 1.79887 units in length, and 1000 planks can only stretch out about 4.8938 units in length.

AC CODE:

#include <iostream>using namespace Std;int main () {int n;d ouble i;int flag=1;while (cin>>n) {double sum=0;for (i=1;i<=n;i++) sum+=1/i;sum/=2;if (flag) {cout<< "# Cards  overhang" <<endl;flag=0;} printf ("%5d     %.3lf\n", n,sum);} return 0;}


Hangzhou Electric HDU ACM 1330 Deck

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.