poj3071--Football(機率計算)

來源:互聯網
上載者:User

標籤:

題目連結:點擊開啟連結

題目大意:給出2^n個隊伍,採用淘汰制比賽,第1和第2比賽,第2和第三比賽,淘汰之後,仍然按順序比賽,p[i][j]:第i支隊伍贏第j支隊伍的機率,問最終哪個隊伍贏的機率最大。

一共會比n場比賽,計算出每一個隊伍贏得機率,找出最大值。

第一場 1對2,3對4,,,,

第二場1、2對3、4,5、6對7、8,,,,

第三場1、2、3、4對5、6、7、8,,

這樣對於第i個隊如果想要在第k場贏,那麼他需要在第k-1場贏的機率乘以∑(j在k-1場贏的機率*i對上j贏機率)

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std ;#define eqs 1e-8double p[200][200] ;double ans[200][200] ;int main() {    int n , m ;    int i , j , len , k , l , r , mid ;    double temp ;    while( scanf("%d", &n) && n != -1 ) {        m = 1<<n ;        for(i = 1 ; i <= m ; i++) ans[n][i] = 1.0 ;        for(i = 1 ; i <= m ; i++)            for(j = 1 ; j <= m ; j++)                scanf("%lf", &p[i][j]) ;        len = 2 ;        while( n-- ) {            k = 1 ;            while( k*len <= m ) {                l = 1+(k-1)*len ;                r = k*len ;                mid = (l+r) / 2 ;                for(i = l ; i <= r ; i++) {                    temp = 0.0 ;                    if( i <= mid ) {                        for(j = mid+1 ; j <= r ; j++)                            temp += ans[n+1][j]*p[i][j] ;                        ans[n][i] = ans[n+1][i]*temp ;                    }                    else {                        for(j = l ; j <= mid ; j++)                            temp += ans[n+1][j]*p[i][j] ;                        ans[n][i] = ans[n+1][i]*temp ;                    }                }                k++ ;            }            len *= 2 ;        }        temp = ans[0][1] ;        k = 1 ;        for(i = 2 ; i <= m ; i++) {            if( ans[0][i]-temp >= eqs ) {                temp = ans[0][i] ;                k = i ;            }        }        printf("%d\n", k) ;    }    return 0 ;}


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

poj3071--Football(機率計算)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.