• 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
  • 相关阅读:
    Myeclipse2013 SVN安装方法以及项目上传到svn服务器
    Gson把json串转换成java实体对象
    使用HttpClient向服务器发送restful post请求
    使用HttpURLConnection向服务器发送post和get请求
    http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/
    CAS单点登录配置[5]:测试与总结
    CAS单点登录配置[4]:客户端配置
    CAS单点登录配置[3]:服务器端配置
    CAS单点登录配置[2]:证书生成
    【Oracle/Java】向三张表各插入百万数据,共用时18分3秒,平均每张表6分钟
  • 原文地址:https://www.cnblogs.com/JDFZ-ZZ/p/14310312.html
Copyright © 2020-2023  润新知