Hangzhou Electric HDU ACM 2048 god, God, and the heavens.

Source: Internet
Author: User

God, God, and the heavens. Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 26034 Accepted Submission (s): 10826


Problem DESCRIPTIONHDU 2006 ' ACM Contest Awards Gala Grand start!
In order to enliven the atmosphere, organizers held a special, prize-rich lottery, the specific requirements of this activity is:

First, all participants in the party put a note with their name in the lottery box;
Then, after all the notes are added, each person takes a note from the box;
Finally, if the note is written on its own name, then "Congratulations, the jackpot!" ”

You can imagine the atmosphere at that time, after all, the winner of the prize is everyone's dream twins signature photo! However, just as all the comedy attempts to design often end in tragedy, no one has won the lottery in the end!

My God, God, and the heavens, how could this be?

But let's not get excited, now that's the problem, can you calculate the probability of this happening?

Not counting? Do you also want to end with a tragedy?!

The first line of input data is an integer c, representing the number of test instances, followed by the C row of data, each line containing an integer n (1<n<=20), representing the number of participants in the lottery.


Output for each test instance, export the percentage that this occurs, the output of each instance is a row, and the result retains two decimal places (rounded), in the exact format, refer to sample output.


Sample Input
12

Sample Output
50%

Authorlcy
The source recursive Solution topic exercise (for beginner) describes itself. n individual n votes, ask everyone to take the wrong vote method number? n Each person is wrong and the wrong row can be described as f (n), then its source must be two possible: the former n-1 individual has been wrong platoon so inevitably nth person took his own ticket. The second kind: the nth person does not own the ticket, then must be one of the former n-1 of the first person's ticket is held by the nth person. For case1: Only the nth person's ticket is interchangeable with one of the former n-1, and n individuals can be in the wrong row, with F (n-1) * (n-1) method. For Case 2: Because the nth person is holding a ticket for one of the former n-1, then it can only be exchanged with a person other than this person, in order to become the source of the N-vote wrong card, the n-1 of the person except the person F (n-2) wrong row, and n-1 a person may be a ticket by N hold. At this time F (n-2) * (n-1), then f (n) = (n-1) * (f (n-1) +f (n-2)); This is the wrong row formula. Pay attention to 0! =1 and the first few of the rows were 0 0 1 ..... Preserves the order multiplier of n with an array. Then you can have a:
#include <iostream>using namespace Std;int main () {int n;double ls[21]={0,0,1};     Double gq[21]={1,1,2};for (int i=3;i<21;i++) {gq[i]=gq[i-1]*i;ls[i]= (i-1) * (Ls[i-1]+ls[i-2]);}   Cin>>n;int T;while (n--) {cin>>t;printf ("%.2lf%%\n", ls[t]/gq[t]*100);} return 0;}

Hangzhou Electric HDU ACM 2048 god, God, and the heavens.

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.