D. Bad Luck Island
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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个布,每一次两个人随机碰上,输的人死掉,问只剩下每一种的概率。

【分析】

  还是一样的配方。。

  f[i][j][k]表示没了i个石头,j个剪刀,k个布的情况下剩下。。。的概率。

  这个也是要移项一下的。

  三个都做一遍就好了。

  【一开始概率求错了,求概率的话做好是用组合数算方案吧不容易错。。

  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<iostream>
  5. #include<algorithm>
  6. using namespace std;
  7. #define Maxn 110
  8.  
  9. double f[][Maxn][Maxn][Maxn];
  10.  
  11. double C(int x)
  12. {
  13. return 1.0*x*(x-)/;
  14. }
  15.  
  16. int main()
  17. {
  18. int r,s,p;
  19. scanf("%d%d%d",&r,&s,&p);
  20. for(int i=r;i>=;i--)//rocks
  21. for(int j=s;j>=;j--)//scissors
  22. for(int k=p;k>=;k--)//papers
  23. {
  24. int N=r+s+p-i-j-k;if(N==) continue;
  25. double PI=1.0/C(N),PP=C(r-i)+C(s-j)+C(p-k),
  26. R=1.0*(r-i),S=1.0*(s-j),P=1.0*(p-k);
  27.  
  28. if(j==s&&k==p) f[][i][j][k]=,f[][i][j][k]=f[][i][j][k]=;
  29. else if(i==r&&k==p) f[][i][j][k]=,f[][i][j][k]=f[][i][j][k]=;
  30. else if(i==r&&j==s) f[][i][j][k]=,f[][i][j][k]=f[][i][j][k]=;
  31. else
  32. {
  33. f[][i][j][k]=(R*S*PI*f[][i][j+][k]+R*P*PI*f[][i+][j][k]+S*P*PI*f[][i][j][k+])/(1.0-PP*PI);
  34. f[][i][j][k]=(R*S*PI*f[][i][j+][k]+R*P*PI*f[][i+][j][k]+S*P*PI*f[][i][j][k+])/(1.0-PP*PI);
  35. f[][i][j][k]=(R*S*PI*f[][i][j+][k]+R*P*PI*f[][i+][j][k]+S*P*PI*f[][i][j][k+])/(1.0-PP*PI);
  36. }
  37. }
  38. printf("%.9lf %.9lf %.9lf\n",f[][][][],f[][][][],f[][][][]);
  39. return ;
  40. }

2017-04-21 21:28:51

【CF540D】 D. Bad Luck Island (概率DP)的更多相关文章

  1. 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 ...

  2. cf540D. Bad Luck Island(概率dp)

    题意 岛上有三个物种:剪刀$s$.石头$r$.布$p$ 其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀 每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉) 问最后仅有$s/r/p$物种生存 ...

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

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

  4. CF540D Bad Luck Island(期望dp)

    传送门 解题思路 比较容易的一道期望\(dp\),设\(f[i][j][k]\)表示石头\(i\)个,剪刀\(j\)个,步子\(l\)个.然后转移的时候用组合数算一下就好了. 代码 #include& ...

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

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

  6. 题解 CF540D 【Bad Luck Island】

    既然没有大佬写题解那本蒟蒻就厚颜无耻地写(水)一(经)下(验)吧 题目要求算出个种人单独留下的存活率 因为n,m,p的范围极小, 那么就可以方便地设3位dp状态dp[i][j][k]表示剩余i个石头, ...

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

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

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

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

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

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

随机推荐

  1. HDU 3065 病毒侵袭持续中 (AC自动机)

    题目链接 Problem Description 小t非常感谢大家帮忙解决了他的上一个问题.然而病毒侵袭持续中.在小t的不懈努力下,他发现了网路中的"万恶之源".这是一个庞大的病毒 ...

  2. Python练习-面向过程编程-模拟Grep命令

    其实这个面向过程编写程序,是编写程序的基础,所以一定要好好掌握 此程序涉及知识点:装饰器,生成器,协程器应用 # 编辑者:闫龙 import os Distinct = [] #定义一个列表用于判断重 ...

  3. Oracle DataTable的数据批量写入数据库

    insert语句,sqldataadapter.update(dataset,tablename);sqlbulkcopy.WriteToServer(datatable);三个方法的性能进行比较: ...

  4. Vue 项目添加 promise polyfill

    1. 安装依赖 npm install es6-promise --save 2. 在 main.js 上面引入: import 'es6-promise/auto'

  5. 采用dlopen、dlsym、dlclose加载动态链接库【总结】【转】

    转自:https://www.cnblogs.com/Anker/p/3746802.html 1.前言 为了使程序方便扩展,具备通用性,可以采用插件形式.采用异步事件驱动模型,保证主程序逻辑不变,将 ...

  6. linux调试工具glibc的演示分析

    偶然中发现,下面的两端代码表现不一样 void main(){ void* p1 = malloc(32);       free(p1); free(p1); // 这里会报double free ...

  7. vue总结 01基础特性

    最近有时间来总结一下vue的知识: 一.vue.js 被定义成一个开发web界面的前端库,是一个非常轻量的工具.vue.js本身具有响应式和组件化的特点. 我们不需要在维护视图和数据的统一上花费大量的 ...

  8. 使用Scrapy命令行工具【导出JSON文件】时编码设置

    Windows 10家庭中文版,Python 3.6.4,virtualenv 16.0.0,Scrapy 1.5.0, 使用scrapy命令行工具建立了爬虫项目(startproject),并使用s ...

  9. SLF4J multiple

    "C:\Program Files\Java\jdk1.8.0_65\bin\java" -Didea.launcher.port=7537 "-Didea.launch ...

  10. linux(vi)常用命令

    常用操作 系统命令 查看主机名 hostname 修改主机名(重启后无效) hostname yang 修改主机名(重启后永久生效) vi /ect/sysconfig/network 修改IP(重启 ...