Hdu-2048, 2048 games

Source: Internet
Author: User

Hdu-2048, 2048 games
The awards gala for Problem DescriptionHDU 2006 '10 ACM contest has begun!
In an active atmosphere, the organizer held a special lucky draw with generous prizes. The specific requirements for this activity are as follows:

First, all participants put a note with their own name in the lottery box;
Then, after all the notes are added, each person takes a note from the box;
Finally, if you write your own name on the obtained note, "Congratulations, you have won the prize !"

You can imagine the warm atmosphere at that time. After all, the winner's prize is a coveted Twins signature photo! However, just as all the comedy attempts to design often end with a tragedy, no one won the prize in this lottery!

How can this happen to my God, God, and God?

However, don't be excited first. Now the problem arises. Can you calculate the probability of such a situation?

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

 

The first line of Input data is an integer C, indicating the number of test instances, followed by data in Row C. Each line contains an integer n (1 <n <= 20 ), indicates the number of people participating in the lucky draw.

 

 

Output for each test instance, please output the percentage of this situation, each instance's Output occupies a row, the results retain two decimal places (rounding), the specific format please refer to sample output.

 

 

Sample Input12

 

Sample Output50.00 % error, WA several times because no global variables are defined. Double way [25], sum; should be defined above,

/* Global variables are automatically initialized to 0, which is a purpose of using global variables in OJ;
The global data is stored in the static zone. If the data volume is large, the stack overflows, the heap slows down, and the static zone is better. */

 

The Code is as follows:

# Include <stdio. h>

Double way [25], sum;

Double fac (int x)
{
Int I;
Double f = 1;
For (I = 1; I <= x; I ++)
F = f * I;
Return f;
}

Int main ()
{
Int c, n, I, j;

While (scanf ("% d", & c )! = EOF)
{
For (I = 1; I <= c; I ++)
{
Scanf ("% d", & n );
Way [1] = 0;
Way [2] = 1;
For (j = 3; j <= n; j ++)
{
Way [j] = (way [J-1] + way [J-2]) * (J-1 );
}
Sum = fac (n );
Printf ("%. 2lf % \ n", (way [n] * 100.0)/sum );
}
}
Return 0;
}

Related Article

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.