zoukankan      html  css  js  c++  java
  • 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 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 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.

    Sample test(s)
    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
     1 #include<stdio.h>
     2 #include<queue>
     3 #include<algorithm>
     4 #include<string.h>
     5 const double eps = 1e-13 ;
     6 int r , s , p ;
     7 const int M = 100 + 5 ;
     8 double dp[M][M][M] ;
     9 
    10 void work ()
    11 {
    12     dp[r][s][p] = 1 ;
    13    for (int i = r ; i >= 0 ; i --) {
    14         for (int j = s ; j >= 0 ; j --) {
    15             for (int t = p ; t >= 0 ; t --) {
    16                 if (i*j + j*t + t*i == 0) continue;
    17                 if (i) dp[i - 1][j][t] += dp[i][j][t] * i * t / (1.0 * (i * j + i * t + j * t)) ;
    18                 if (j) dp[i][j - 1][t] += dp[i][j][t] * j * i / (1.0 * (i * j +i * t +j * t)) ;
    19                 if (t) dp[i][j][t - 1] += dp[i][j][t] * t * j / (1.0 * (i * j + i * t + j * t )) ;
    20             }
    21         }
    22     }
    23 }
    24 int main()
    25 {
    26    // freopen ("a.txt" , "r" , stdin ) ;
    27     while (~ scanf ("%d%d%d" , &r , &s , &p)) {
    28         memset (dp , 0 , sizeof(dp)) ;
    29         work () ;
    30         double sum = 0 ;
    31         for (int i = 1 ; i <= r ;i ++) {
    32             if (dp[i][0][0] > eps) {
    33                 sum += dp[i][0][0] ;
    34             }
    35         }
    36         printf ("%.12f " , sum );
    37         int i ;
    38         for (sum = 0 ,i = 1 ; i <= s ;i ++) {
    39             if (dp[0][i][0] > eps) {
    40                 sum += dp[0][i][0] ;
    41             }
    42         }
    43         printf ("%.12f " , sum ) ;
    44         for (sum = 0 , i = 1 ; i <= p ;i ++) {
    45             if (dp[0][0][i] > eps) {
    46                 sum += dp[0][0][i] ;
    47             }
    48         }
    49         printf ("%.12f
    " , sum ) ;
    50     }
    51     return 0 ;
    52 }
    View Code

    Let's count the values dp[r][s][p] — the probability of the situation when r rocks, s scissors and p papers are alive. The initial probability is 1, and in order to calculate the others we should perform the transitions.

    Imagine we have r rocks, s scissors and p papers. Let's find the probability of the rock killing scissors (the other probabilities are calculated in the same way). The total number of the possible pairs where one species kills the other one is rs + rp + sp, and the number of possible pairs (rock, scissors) is rs. As all meetings are equiprobable, the probability we want to find is . This is the probability with which we go the the state dp[r][s — 1][p], with the number of scissors less by one.

    In the end, for example, to get the probability of the event that the rocks are alive, we should sum all values dp[i][0][0] for i from 1 to r (the same goes to the other species).

  • 相关阅读:
    Things You Should Know
    因为web.config配置,导致(当前不会命中断点,还没有为该文档加载任何符号)
    【HTML5 Canvas游戏开发】笔记(二) 显示一张图片
    【HTML5 Canvas游戏开发】笔记(一) 概述和基础讲解
    const char* pcr&char* const pcr
    【Python扩展阅读【转】EasyGui 学习文档【超详细中文版】】
    【Python扩展阅读【转】】字符串的方法及注释
    【Python⑥】python的缩进,条件判断和循环
    【Python⑤】python序列---list和tuple
    【Python④】python恼人的字符串,格式化输出
  • 原文地址:https://www.cnblogs.com/get-an-AC-everyday/p/4471200.html
Copyright © 2011-2022 走看看