Nowcoder 202h-Card Game

Source: Internet
Author: User

Topic links

Title Description Beckham likes to play card games. There are n types of cards in a game system, where M is rare. Beckham will have a card every time after winning a computer duel, and then the system randomly chooses one of the n cards to give to Beckham. Ordinary cards may appear multiple times, and rare cards will not be pumped repeatedly. Beckham wanted to collect K rare cards, and she wanted to know how many times it would take to win to achieve that goal. Input Description: Data has multiple groups, the first line an integer t represents the number of data groups.
One row per group of data, three integers n,m,k.1≤t≤100, 1≤n≤10$$$^5$$$,1≤m≤n,1≤k≤m output Description: For each set of data, the output shape such as "Case #x: Y", where x is the number of this set of data (starting from 1), Y is the group The answer to the data. The absolute error or relative error of the answer is considered correct within 10$$$^{-6}$$$. Input 2
5 2 1
40 9 5 Output case #1:2.5
Case #2:28.1146825397 test instructions Altogether n goods, of which n-m items are drawn back, M-items are drawn to not put back. Draw the K of the M-items to ask for the desired number of times to draw. Analysis If you have no idea of this topic, then take a look at "linear algebra and probability statistics" in the classic shooting mathematical expectations of the problem bar.
The basketball player shoots continuously until the hit is reached. Let's say that the probability of his hitting is p, and the shots are independent of each other. X indicates the number of shots needed for the first hit, and the mathematical expectation of X. So X obeys the following geometric distributions $$$$$$\begin{align}& P (x=k) = (1-p) ^{k-1}p \& E (X) =\sum_{k=1}^{\infty}k (1-p) ^kp=p\sum_{k=1}^{\ Infty}k (1-p) ^k=p\frac{1}{p^2}=\frac{1}{p} \ \end{align}$$$$$$ So for this problem, the equivalent of a total of one to vote for the K ball. First to find the number of rare cards to expect, and the above process is the same, the probability of the rare card is $$ $p =\frac{m}{n}$$$, so the expectation is $$ $EX =\frac{n}{m}$$$, and then the second time to draw the rare card of the number of expectations, in fact, is a " Throw the ball experiment ", only the probability becomes $$ $p =\frac{m-1}{n-1}$$$, but the expectation also changes correspondingly to $$ $EX =\frac{n-1}{m-1}$$$. So the number of times the 1~k is expected, the same method can be obtained. sum up sorry my linear algebra teacher code
#include <stdio.h>intMain () {intT; intn,m,k; scanf ("%d",&T); Doubleans=0;  for(intKase=1; kase<=t;++Kase) {scanf ("%d%d%d",&n,&m,&k); printf ("Case #%d:", Kase); Ans=0.0;  for(intI=0; i<=k-1; i++) ans+=1.0* (n-i)/(M-i); printf ("%.7f\n", ans); }}

Nowcoder 202h-Card Game

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.