UV 10169 Urn-ball Probabilities!

Source: Internet
Author: User

UVA_10169

This question can obviously pre-process the results and then use them for reference. It is not difficult to calculate the formula. When calculating the number of 0, we use a conversion like X = 10 ^ (log10 (X), so we only need to calculate-log10 (X).

In addition, it should be noted that overflow must be avoided when integer multiplication is involved. If the intermediate result is beyond the int range, it can be forcibly converted to double or long before calculation.

# Include <stdio. h>
# Include <string. h>
# Include <math. h>
# Define MAXD 1000010
Double f [MAXD];
Int d [MAXD];
Void prepare ()
{
Int I, j, k;
Double p1 = 1, p2 = 0;
For (I = 1; I <1000000; I ++)
{
P1 = p1 * (double) I * I + I-1)/(double) I * I + I );
P2 + = log10 (double) I * I + I );
F [I] = 1-p1;
D [I] = (int) (p2-fmod (p2, 1) + 0.5 );
}
}
Int main ()
{
Int n;
Prepare ();
While (scanf ("% d", & n) = 1)
{
If (n = 0)
Printf ("0.000000 0 \ n ");
Else
Printf ("%. 6lf % d \ n", f [n], d [n]);
}
Return 0;
}


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.