UPC 3025 fleecing the Raf?e

Source: Internet
Author: User

fleecing the Raf?e time limit: 2 Sec memory limit: Up to MB special Judge
Submitted by: 179 Resolution: 49
Submitted State [Discussion Version] [Propositional person: external import] Title description A tremendously exciting raf?e is being held,with some tremendously exciting prizes being given out. All the chance of being a winner are to put a piece of paper with your name on it in the Raf?e box. The lucky winners of the P prizes is decided by drawing P-Names from the box. When a piece of paper with a name have been drawn it is not put back into the Box–each person can win at the most one prize.
Naturally, it's against the raf?e rules to put your name in the box more than once. However, it was only cheating if you were actually caught, and since not even the raf?e organizers want to spend time Checki Ng all the names in the box and the only-the-caught is if your name ends up being drawn for more than one of the Prizes. This means, cheating and placing your name more than once can sometimes increase your chances of winning a prize.
You know the number of names in the Raf?e box placed by other people, and the number of the prizes that'll be given out. By carefully choosing what many times to add your own name to the box, how large can do your chances of winning a PRI Ze (i.e., the probability that your name is drawn exactly once)?

Enter the input consists of a single line containing II integers n and P (2≤p≤n≤106), where n is the number of names I n the Raf?e box excluding yours, and P is the number of prizes that would be given away.

Output containing the maximum possible probability of winning a prize, accurate up to an absolute error of 10-6.

Sample input
3 2

Sample output
0.6

Tips

Sample Input 2
23 5
Sample Output 2
0.45049857550

Test instructions

In addition to your other n individuals write a note with a name in the lottery box, a total of P awards, you can write any X-note into the lottery box, you can't win two times, the best solution to the X-win probability of the most.

Analysis

The probability problem, the mathematics pushes the formula, but asks the combination number process to be the detonation precision, therefore must bashi the sub-simplification.

///Author:kissheart///#include <stdio.h>#include<algorithm>#include<iostream>#include<string.h>#include<vector>#include<stdlib.h>#include<math.h>#include<queue>#include<deque>#include<ctype.h>#include<map>#include<Set>#include<stack>#include<string>#defineINF 0x3f3f3f3f#defineFast_io Ios::sync_with_stdio (False)Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-6;Const intmax=1e6+Ten;Const intmod=1e9+7; typedefLong Longll;using namespacestd;#defineGCD (A, B) __gcd (A, B)Inline ll LCM (ll A,ll b) {returnA/GCD (A, b) *b;} inline ll Qpow (ll A,ll b) {ll r=1, T=a; while(b) {if(b&1) r= (r*t)%mod;b>>=1; t= (t*t)%mod;}returnR;} inline ll Inv1 (ll b) {returnQpow (b,mod-2);} inline ll EXGCD (ll A,ll b,ll&x,ll &y) {if(!B) {x=1; y=0;returnA;} ll R=EXGCD (b,a%b,y,x); y-= (A/b) *x;returnR;} inline ll read () {ll x=0, f=1;CharC=getchar (); for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1; for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0';returnx*F;}//freopen ("In.txt", "R", stdin);//freopen ("Data.txt", "w", stdout);intMain () {intn,p; intx; scanf ("%d%d",&n,&p); if(n==1) {printf ("0.5\n"); return 0; } x=n/(P-1); Doubleans=1.0*x*p/(x+n-p+1);  for(intI=0; i<=p-2; i++) {ans=ans* (ni); Ans=ans/(x+n-i); } printf ("%.11lf\n", ans); return 0;}
View Code

UPC 3025 fleecing the Raf?e

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.