题目链接:https://vjudge.net/contest/226823#problem/D

The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p 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.

Examples

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

题意:

有r个石头,s个剪刀,p个布。每次都随机挑出,问:最后只剩下石头、剪刀、布的概率分别是多少?

题解:

1.设dp[i][j][k]为:剩余i个石头,j个剪刀,k个布的概率。

2.可知:如果选到的两个是同类型,那么这一轮是无意义的,且对结果毫无影响,所以可忽略这种情况,只需考虑两者不同的情况。

3.假设当前还剩余i个石头,j个剪刀,k个布,那么下一轮抽到石头和剪刀的概率为(不需考虑同类型的):(i*j)/(i*j+i*k+j*k),而此种情况的结果为[i][j-1][k],所以dp[i][j-1][k] += (i*j)/(i*j+i*k+j*k)*dp[i][j][k]。同理剩下的两种情况。

代码如下:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <cstdlib>
  6. #include <string>
  7. #include <vector>
  8. #include <map>
  9. #include <set>
  10. #include <queue>
  11. #include <sstream>
  12. #include <algorithm>
  13. using namespace std;
  14. typedef long long LL;
  15. const double eps = 1e-;
  16. const int INF = 2e9;
  17. const LL LNF = 9e18;
  18. const int MOD = 1e9+;
  19. const int MAXN = 1e2+;
  20.  
  21. double dp[MAXN][MAXN][MAXN];
  22. int main()
  23. {
  24. int n, m, p;
  25. while(scanf("%d%d%d",&n,&m,&p)!=EOF)
  26. {
  27. memset(dp, , sizeof(dp));
  28. dp[n][m][p] = 1.0;
  29. for(int i = n; i>=; i--)
  30. for(int j = m; j>=; j--)
  31. for(int k = p; k>=; k--)
  32. {
  33. if(i&&j) dp[i][j-][k] += (1.0*i*j/(i*j+j*k+i*k))*dp[i][j][k];
  34. if(j&&k) dp[i][j][k-] += (1.0*j*k/(i*j+j*k+i*k))*dp[i][j][k];
  35. if(i&&k) dp[i-][j][k] += (1.0*i*k/(i*j+j*k+i*k))*dp[i][j][k];
  36. }
  37.  
  38. double r1 = , r2 = , r3 = ;
  39. for(int i = ; i<=n; i++) r1 += dp[i][][];
  40. for(int i = ; i<=m; i++) r2 += dp[][i][];
  41. for(int i = ; i<=p; i++) r3 += dp[][][i];
  42.  
  43. printf("%.10f %.10f %.10f\n", r1,r2,r3);
  44. }
  45. }

CodeForces - 540D Bad Luck Island —— 求概率的更多相关文章

  1. CF 540D——Bad Luck Island——————【概率dp】

    Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  2. Codeforces B. Bad Luck Island(概率dp)

    题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces 540D Bad Luck Island - 概率+记忆化搜索

    [题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...

  4. codeforces 540D Bad Luck Island (概率DP)

    题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...

  5. Codeforces 540D Bad Luck Island

    http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...

  6. 540D - Bad Luck Island(概率DP)

    原题链接:http://codeforces.com/problemset/problem/540/D 题意:给你石头.剪刀.布的数量,它们之间的石头能干掉剪刀,剪刀能干掉布,布能干掉石头,问最后石头 ...

  7. CodeForces 540D Bad Luck Island (DP)

    题意:一个岛上有石头,剪刀和布,规则就不用说了,问你最后只剩下每一种的概率是多少. 析:很明显的一个概率DP,用d[i][j][k]表示,石头剩下 i 个,剪刀剩下 j 个,布剩下 k 个,d[r][ ...

  8. 【CF540D】 D. Bad Luck Island (概率DP)

    D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. CF#301 D:Bad Luck Island (概率dp)

    D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j] ...

随机推荐

  1. 【Salvation】——人物角色动画实现

    写在前面:这个角色动画主要使用JavaScript编写脚本,在Unity3D游戏引擎的环境中实现. 一.显示角色并实现镜像效果 1.显示贴图: create→cube→修改名称为player,位置归0 ...

  2. 【Python】学习笔记十五:循环对象

    循环对象 所谓的循环对象,包含有一个next()方法(python3中为__next__() ),这个方法的目的就是进行到下一个结果,而在结束一系列结果之后,举出StopIteration错误 当一个 ...

  3. Oracle无安装客户端安装方法

    一. 1)下载Oracle客户端:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.htm ...

  4. Erlang 督程 启动和结束子进程

    1.督程: test_sup 2.子进程:test_gen_server 3.子进程规格Spec: { test_gen_server, {test_gen_server, start_link, [ ...

  5. 美柚“姨妈假”上头条,App事件营销怎么做

        近期,微博上有关"姨妈假"的话题异常火爆,事件源于厦门互联网企业美柚所推出的一项"奇葩福利"------女员工可向公司请姨妈假.此事经媒体报道.微博爆料 ...

  6. select设置innerHMTL

    select控件在标准浏览器下可以直接innerHTML设置内容,IE则不行. HTML结构: <form name="form1"> <select name= ...

  7. 电容有什么作用?为什么cpu电源引脚都并联一个电容?

    管理 随笔- 17  文章- 1  评论- 1  电容有什么作用?为什么cpu电源引脚都并联一个电容?   正文: 参考资料:http://blog.sina.com.cn/s/blog_7880d3 ...

  8. 15:取近似值ApproximateValue

    题目描述 写出一个程序,接受一个正浮点数值,输出该数值的近似整数值.如果小数点后数值大于等于5,向上取整:小于5,则向下取整. 输入描述:输入一个正浮点数值 输出描述:输出该数值的近似整数值 输入例子 ...

  9. CentOS中文乱码的问题

    修改CentOS 6.4 root用户的系统默认语言设置 最近用Virtual Box 虚拟了一个CentOS系统,版本6.4,安装时使用简体中文.发现用普通用户登录的时候 设置语言环境为Englis ...

  10. Oracle SQL性能优化 - 根据大表关联更新小表

    需求: 小表数据量20w条左右,大表数据量在4kw条左右,需要根据大表筛选出150w条左右的数据并关联更新小表中5k左右的数据. 性能问题: 对筛选条件中涉及的字段加index后,如下常规的updat ...