HDU 2048 God, God, and God

Source: Internet
Author: User
God, God, and God

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)

Total submission (s): 17226 accepted submission (s): 7336

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 Input

12

Sample output

50.00%

Idea: calculate the probability of an error

That is, all errors (error rows)/all rows;

Principle of wrong arrangement: http://blog.csdn.net/deng_hui_long/article/details/9495539

Formula of the error: A [n] = (n-1) * (a [n-1] + A [N-2]); A [1] = 0; A [2] = 1; A [3] = 2;

Full row: n!

That is, a [n]/n

import java.text.DecimalFormat;import java.util.*;import java.io.*;import java.math.BigDecimal;import java.math.BigDecimal;public class Main {public static BigDecimal big[]=new BigDecimal[21];public static BigDecimal  big1[]=new BigDecimal [21];public static void main(String[] args) {Scanner sc=new Scanner(new BufferedInputStream(System.in));DecimalFormat dec=new DecimalFormat("0.00");int k=sc.nextInt();jieCheng();cuoPai();for(int i=0;i<k;i++){int m=sc.nextInt();double d1=big1[m].doubleValue();double d2=big[m].doubleValue();System.out.println(dec.format(d1/d2*100.0)+"%");}}public static void jieCheng(){big[1]=BigDecimal.valueOf(1); for(int i=2;i<21;i++){big[i]=BigDecimal.valueOf(i).multiply(big[i-1]);}}public static void cuoPai(){big1[1]=BigDecimal.valueOf(0);big1[2]=BigDecimal.valueOf(1);big1[3]=BigDecimal.valueOf(2);for(int i=4;i<21;i++){big1[i]=BigDecimal.valueOf(i-1).multiply(big1[i-1].add(big1[i-2]));}}}

 

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.