• CF1392H ZS Shuffles Cards


    Description

    zscoder has a deck of $n+m$ custom-made cards, which consists of $n$ cards labelled from $1$ to $n$ and $m$ jokers. Since zscoder is lonely, he wants to play a game with himself using those cards.

    Initially, the deck is shuffled uniformly randomly and placed on the table. zscoder has a set $S$ which is initially empty.

    Every second, zscoder draws the top card from the deck.

    If the card has a number $x$ written on it, zscoder removes the card and adds $x$ to the set $S$ .
    If the card drawn is a joker, zscoder places all the cards back into the deck and reshuffles (uniformly randomly) the $n+m$ cards to form a new deck (hence the new deck now contains all cards from $1$ to $n$ and the $m$ jokers). Then, if $S$ currently contains all the elements from $1$ to $n$ , the game ends. Shuffling the deck doesn't take time at all.
    What is the expected number of seconds before the game ends? We can show that the answer can be written in the form $frac{P}{Q}$ where $P,Q$ are relatively prime integers and $Q eq 0 mod 998244353$
    Output the value of $(P cdot Q^{-1})$

    Solution

    考虑先计算每一轮摸牌多少次,再考虑期望抽到Joker次数(轮数)

    每一张数字牌在所有Joker前的概率为$frac {1}{m+1}$,所以期望每一轮抽到的数字牌张数为$frac{n}{m+1}+1$

    设$f_k$为还剩$k$个数没有进入集合时的期望步数,有

    $$f_k=frac{m}{m+k}(f_k+1)+frac{k}{m+k}f_{k-1}$$

    解得

    $$f_k=f_{k-1}+frac{m}{k}$$

    $f_1$的值为$m+1$,则$f_n=1+msum _{i=1}^nfrac{1}{i} $

    最后两个数相乘

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int n,m;
    long long inv[2000005]={0,1},ans;
    const long long mod=998244353;
    inline int read(){
        int f=1,w=0;
        char ch=0;
        while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9') w=(w<<1)+(w<<3)+ch-'0',ch=getchar();
        return f*w;
    }
    int main(){
        for(int i=2;i<=2000001;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        n=read(),m=read();+
        for(int i=1;i<=n;i++)(ans+=inv[i])%=mod;
        printf("%lld
    ",(ans*m%mod+1)*(n*inv[m+1]%mod+1)%mod);
        return 0;
    }
    ZS Shuffles Cards
  • 相关阅读:
    oracle 存储过程的基本语法
    Silverlight :服务器返回错误: NotFound 错误
    利用CSS定位背景图片 backgroundposition
    解决 asp.net 伪静态 IIS设置后 直正HTML无法显示的问题
    输入框下拉列表提示
    同步文本框内容的JS代码
    判断文本框只能输入中文汉字的代码
    如何解决padding标记在ie7、ie6以及firefox中的兼容问题
    ASP.NET用URLRewriter.dll实现伪静态
    滑动效果,适合做faq或menu
  • 原文地址:https://www.cnblogs.com/JDFZ-ZZ/p/14310312.html
Copyright © 2020-2023  润新知