zoukankan      html  css  js  c++  java
  • Codeforces 540 D Bad Luck Island

    Discription

    The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.

    Input

    The single line contains three integers rs and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.

    Output

    Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.

    Example

    Input
    2 2 2
    Output
    0.333333333333 0.333333333333 0.333333333333
    Input
    2 1 2
    Output
    0.150000000000 0.300000000000 0.550000000000
    Input
    1 1 3
    Output
    0.057142857143 0.657142857143 0.285714285714


    方程的转移比较显然23333,问题是怎么消除后效性。
    也就是,每次f[i][j][k] 有 (C(i,2) + C(j,2) + C(k,2))/C(i+j+k,2) 的概率走到自己,
    那么我们用一下生成函数(1+p+p^2+...=1/(1-p))的基本性质就可以算出f[i][j][k]期望走到自己多少次
    ,然后再转移即可。

    #include<bits/stdc++.h>
    #define ll long long
    #define D double
    using namespace std;
    D f[105][105][105];
    int n,m,k,C[355];
    
    inline void init(){
    	C[0]=C[1]=0;
    	for(int i=2;i<=320;i++) C[i]=C[i-1]+i-1;
    }
    
    inline void dp(){
    	f[n][m][k]=1.00;
    	for(int i=n;i>=0;i--)
    	    for(int j=m;j>=0;j--)
    	        for(int u=k;u>=0;u--) if((i>0)+(j>0)+(u>0)>=2){
    	        	f[i][j][u]=f[i][j][u]*C[i+j+u]/(double)(C[i+j+u]-C[i]-C[j]-C[u]);
    	        	if(i) f[i-1][j][u]+=f[i][j][u]*i*u/(double)C[i+j+u];
    	        	if(j) f[i][j-1][u]+=f[i][j][u]*i*j/(double)C[i+j+u];
    	        	if(u) f[i][j][u-1]+=f[i][j][u]*j*u/(double)C[i+j+u];
    			}
    }
    
    inline void output(){
    	D ans;
    	ans=0;
    	for(int i=1;i<=n;i++) ans+=f[i][0][0];
    	printf("%.11lf ",ans);
    	ans=0;
    	for(int i=1;i<=m;i++) ans+=f[0][i][0];
    	printf("%.11lf ",ans);
    	ans=0;
    	for(int i=1;i<=k;i++) ans+=f[0][0][i];
    	printf("%.11lf",ans);
    }
    
    int main(){
    	init();
    	scanf("%d%d%d",&n,&m,&k);
    	dp();
    	output();
    	return 0;
    }
    

      

     
  • 相关阅读:
    k3 cloud采购入库单单位问题
    k3 cloud没有使用协同平台开发时候的调试方式
    k3 cloud写插件不重启IIS热更新简单配置
    k3 cloud部署包中的安装包变成了浏览器,不能安装
    逻辑门
    JDBC的架构设计
    非功能性约束之性能(1)-性能银弹:缓存
    C#性能优化杂七杂八的总结
    QT QToolTip
    IDEA spotbugs使用
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8597359.html
Copyright © 2011-2022 走看看