Neuoj 1484 probability DP

Source: Internet
Author: User



1484:hengheng eat noodles time limit: 1 Sec memory limit:
submitted: resolution: 17
Submitted State [Discussion Version] Title Description

As we all Know,hengheng (Big cow), the very look forward to meizi and he often declare the he want to find a meizi. As Hengheng ' s admirer, Jiajia decides to help Hengheng to achieve he dream in Christmas Day. Jiajia asks Hengheng to eat noodles with a pretty meizi (don ' t ask why Jiajia didn ' t chase this pretty meizi). When eating noodles, Hengheng was so excited that he wants the QQ of the Meizi. However, a unlucky thing happen. The pretty Meizi says she won ' t give Hengheng her QQ unless Hengheng can solve her question. Hengheng promise without hesition. The pretty Meizi picks up a noodle and say with sexy voice, "We all know a noodle have both Ends,and now I have n noodles, so There is 2*n ends at all. Out of interest,i would link these ends Randomly,and then I wonder the mathematical expectation of the circle I could get. " Although Hengheng is big cow, he can ' t wait for get the QQ so he can ' t think as long as he see the pretty. So he ask Jiajia to solve the problem for him. Luckily,after Ms,jiajia give the right answer. And Hengheng got the QQ successfully. Now, if you is Jiajia, could solve the problem within MS and help Hengheng get the QQ.

Input

The first line is a integer t,indicate the number of cases. (t<=10)
Follow,there is a integer n,imply the amount of noodles. (n<=10^6)

Output

For each case, print a double e,represent the mathematical expectation. (E retain 6 decimal)

Sample input
3124
Sample output
1.0000001.3333331.676190
Tips


Source

New Star Race 2014

Submitted State [Discussion Version] anything about the problems admin:admin
All Copyright Reserved 2010-2015 neu-acm TEAM
GPL2.0 2003-2013 hustoj Project TEAMTest Instructions: There are n noodles, 2n endpoints, randomly connected to ask to form the ring of expectation

Probability DP Ah, so that d[i] represents the former I root noodles can form the expectations, then there are two possible, I root and I am connected to expect for d[i-1]+1, the first I do not connect with themselves, expect for d[i].

The probability of root I and myself being connected is 1/(2*i-1). The full probability formula is fine.


#include <stdio.h> #include <stdlib.h>const int maxn = 1e6 + 5;double d[maxn];void init (int n) {    d[0] = 0;
   for (int i = 1; I <= n; i++) {        double p = 1.0/(2*i-1);        D[i] =  p* (1+d[i-1]) + d[i-1]* (1-p);}    } int main (int argc, char const *argv[]) {    int t;    scanf ("%d", &t);    Init (1000000);    while (t--) {        int n;        scanf ("%d", &n);        printf ("%.6f\n", D[n]);    }    return 0;}





1484:hengheng eat noodles time limit: 1 Sec memory limit:
submitted: resolution: 17
Submitted State [Discussion Version] Title Description

As we all Know,hengheng (Big cow), the very look forward to meizi and he often declare the he want to find a meizi. As Hengheng ' s admirer, Jiajia decides to help Hengheng to achieve he dream in Christmas Day. Jiajia asks Hengheng to eat noodles with a pretty meizi (don ' t ask why Jiajia didn ' t chase this pretty meizi). When eating noodles, Hengheng was so excited that he wants the QQ of the Meizi. However, a unlucky thing happen. The pretty Meizi says she won ' t give Hengheng her QQ unless Hengheng can solve her question. Hengheng promise without hesition. The pretty Meizi picks up a noodle and say with sexy voice, "We all know a noodle have both Ends,and now I have n noodles, so There is 2*n ends at all. Out of interest,i would link these ends Randomly,and then I wonder the mathematical expectation of the circle I could get. " Although Hengheng is big cow, he can ' t wait for get the QQ so he can ' t think as long as he see the pretty. So he ask Jiajia to solve the problem for him. Luckily,after Ms,jiajia give the right answer. And Hengheng got the QQ successfully. Now, if you is Jiajia, could solve the problem within MS and help Hengheng get the QQ.

Input

The first line is a integer t,indicate the number of cases. (t<=10)
Follow,there is a integer n,imply the amount of noodles. (n<=10^6)

Output

For each case, print a double e,represent the mathematical expectation. (E retain 6 decimal)

Sample input
3124
Sample output
1.0000001.3333331.676190
Tips


Source

New Star Race 2014

Submitted State [Discussion Version] anything about the problems admin:admin
All Copyright Reserved 2010-2015 neu-acm TEAM
GPL2.0 2003-2013 hustoj Project TEAM

Neuoj 1484 probability DP

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.