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 r, s 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
2 2 2
0.333333333333 0.333333333333 0.333333333333
2 1 2
0.150000000000 0.300000000000 0.550000000000
1 1 3
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;
}
Codeforces 540 D Bad Luck Island的更多相关文章
- Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP
D. Bad Luck Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/pr ...
- CodeForces - 540D Bad Luck Island —— 求概率
题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...
- Codeforces B. Bad Luck Island(概率dp)
题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- cf.301.D. Bad Luck Island(dp + probabilities)
D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【CF540D】 D. Bad Luck Island (概率DP)
D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF#301 D:Bad Luck Island (概率dp)
D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j] ...
- CF 540D——Bad Luck Island——————【概率dp】
Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 540D Bad Luck Island
http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...
- 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)
题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
随机推荐
- prototype中的ajax异步加载
jquery前台处理: var param = {a:a}; $.post("*.do",param,function(data) { var columHtml = " ...
- urlrewrite地址重写实例
urlrewrite主要实现后天请求中的地址重写,防止被安全漏洞盲注入 http://tuckey.org/urlrewrite/ 下载最新的jar 下面是使用说明: 1.下载urlrewrite,官 ...
- 【二分 贪心】bzoj3477: [Usaco2014 Mar]Sabotage
科学二分姿势 Description Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's mi ...
- Windows10安装MariaDB
截至写这篇博客为止,MariaDB官方的稳定版本为,详情访问官方地址:https://downloads.mariadb.org/ 安装之前先简单说一下MariaDB: MariaDB ...
- Day13有参装饰器,三元表达式,匿名函数
多个装饰器: 加载顺序:由下而上 执行顺序:由上而下 有参装饰器: 闭包,给函数传参的一种方法 当装饰器内需要参数时,可以采用闭包形式给其传参,第三层函数接收完参数时,就变为无参装饰器 三元表达式: ...
- foxmial 和 outlook设置问题
您可以使用支持POP3的客户端软件(例如Foxmail或Outlook)收发您的邮件.请配置您的电子邮件客户端,以下载QQ邮箱邮件. 了解如何进行配置,请单击您的电子邮件客户端名称: Foxmail设 ...
- Java-改变Class
改变一个Class对象的类型 package com.tj; public class MyClass2 { public static void main(String[] args) { Obje ...
- JMeter学习笔记21-如何添加思考时间
本文来介绍,JMeter如何插入思考时间.前面介绍过一个真实的性能测试场景,是需要加入思考时间,来模拟真实用户行为.本文就来介绍,如何在三个请求之间添加思考时间. 1. 在Test Plan下新建一个 ...
- Leetcode 391.完美矩形
完美矩形 我们有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域. 每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1 ...
- Codeforces Round #265 (Div. 1)
D. World of Darkraft - 2 time limit per test 2 seconds memory limit per test 256 megabytes input sta ...