• P2059 [JLOI2013]卡牌游戏 概率DP


    link:https://www.luogu.org/problemnew/show/P2059

    题意:

    有n个人,类似约瑟夫环的形式踢人,但是报的数是不同的,是在给定的许多数中随机抽取,问最后第i个人赢的概率;

    思路: 

    假设dp[i][j],表示剩下i个人,从庄家后 第 j 个人在本轮不被淘汰的概率

    我们可以首先枚举庄家抽到的卡牌k,得到这一轮被淘汰的人的位置c。当然,如果c=j ,就不要考虑了(因为这表示此轮第j个人被淘汰)。

    而第c个人被淘汰之后,剩下的i−1个人要组成一个新的环,庄家为第c个人的下一个。容易算出,当c>j时,第j个人是新的环里从新庄家数起的第i−c+j个人,当c<j时,第j个人是新的环里从新庄家数起的第j−c个人。

    #include <algorithm>
    #include  <iterator>
    #include  <iostream>
    #include   <cstring>
    #include   <cstdlib>
    #include   <iomanip>
    #include    <bitset>
    #include    <cctype>
    #include    <cstdio>
    #include    <string>
    #include    <vector>
    #include     <stack>
    #include     <cmath>
    #include     <queue>
    #include      <list>
    #include       <map>
    #include       <set>
    #include   <cassert>
    
    /*
    
    ⊂_ヽ
      \\ Λ_Λ  来了老弟
       \('ㅅ')
        > ⌒ヽ
       /   へ\
       /  / \\
       レ ノ   ヽ_つ
      / /
      / /|
     ( (ヽ
     | |、\
     | 丿 \ ⌒)
     | |  ) /
    'ノ )  Lノ
    
    */
    
    using namespace std;
    #define lson (l , mid , rt << 1)
    #define rson (mid + 1 , r , rt << 1 | 1)
    #define debug(x) cerr << #x << " = " << x << "
    ";
    #define pb push_back
    #define pq priority_queue
    
    
    
    typedef long long ll;
    typedef unsigned long long ull;
    //typedef __int128 bll;
    typedef pair<ll ,ll > pll;
    typedef pair<int ,int > pii;
    typedef pair<int,pii> p3;
    
    //priority_queue<int> q;//这是一个大根堆q
    //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
    #define fi first
    #define se second
    //#define endl '
    '
    
    #define boost ios::sync_with_stdio(false);cin.tie(0)
    #define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
    #define max3(a,b,c) max(max(a,b), c);
    #define min3(a,b,c) min(min(a,b), c);
    
    
    const ll oo = 1ll<<17;
    const ll mos = 0x7FFFFFFF;  //2147483647
    const ll nmos = 0x80000000;  //-2147483648
    const int inf = 0x3f3f3f3f;
    const ll inff = 0x3f3f3f3f3f3f3f3f; //18
    const int mod = 1e9+7;
    const double esp = 1e-8;
    const double PI=acos(-1.0);
    const double PHI=0.61803399;    //黄金分割点
    const double tPHI=0.38196601;
    
    
    template<typename T>
    inline T read(T&x){
        x=0;int f=0;char ch=getchar();
        while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
        while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
        return x=f?-x:x;
    }
    
    inline void cmax(int &x,int y){if(x<y)x=y;}
    inline void cmax(ll &x,ll y){if(x<y)x=y;}
    inline void cmin(int &x,int y){if(x>y)x=y;}
    inline void cmin(ll &x,ll y){if(x>y)x=y;}
    
    /*-----------------------showtime----------------------*/
    
                const int maxn = 55;
                int p[maxn];
                double dp[maxn][maxn];
    int main(){
                int n,m;
                scanf("%d%d", &n, &m);
                rep(i, 1, m) scanf("%d", &p[i]);
                dp[1][0] = 1.0;
                for(int i=2; i<=n; i++){
                 //   for(int s = 0; s <i; s++){
                        for(int j=0; j<i; j++){
                            for(int t=1; t<=m; t++){
                                int dx = (p[t]-1) % i;
                                if(dx == j) continue;
                                if(dx > j) {
    
                                    dp[i][j] += dp[i-1][i - dx + j - 1]*1.0/m;
    
                                }
                                else dp[i][j] += dp[i-1][j - dx - 1]*1.0/m;
                            }
                        }
                   // }
                }
    
                for(int i=1; i<=n; i++) printf("%.2f%% ", 100*dp[n][i - 1]);
                return 0;
    }
    /*
    
       
    */
    View Code
  • 相关阅读:
    解剖SQLSERVER 第十二篇 OrcaMDF 行压缩支持(译)
    解剖SQLSERVER 第十三篇 Integers在行压缩和页压缩里的存储格式揭秘(译)
    解剖SQLSERVER 第十四篇 Vardecimals 存储格式揭秘(译)
    解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译)
    解剖SQLSERVER 第七篇 OrcaMDF 特性概述(译)
    解剖SQLSERVER 第八篇 OrcaMDF 现在支持多数据文件的数据库(译)
    解剖SQLSERVER 第九篇 OrcaMDF现在能通过系统DMVs显示元数据(译)
    解剖SQLSERVER 第十篇 OrcaMDF Studio 发布+ 特性重温(译)
    解剖SQLSERVER 第十一篇 对SQLSERVER的多个版本进行自动化测试(译)
    解剖SQLSERVER 第三篇 数据类型的实现(译)
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/10426236.html
Copyright © 2020-2023  润新知