Hatena::Grouptopcoder

TopCoderの問題を解く

解いた問題の一覧表

2010-02-07

TheFansAndMeetingsDivTwo

| 19:32

問題文, SRM 460

JohnとBrusが同じ数のファンに会える確率を求める。苦手意識のある確率の問題だったが、全パターンを調べる方法であっさり解けた。以下の回答は3重ループだが、2重ループでも解けると思う。

439.61/500

class TheFansAndMeetingsDivTwo {
public:
    double find(vector <int> minJ, vector <int> maxJ, vector <int> minB, vector <int> maxB) {
        const int size = minJ.size();
        double result = 0.0;
        for (int i = 0; i < size; i++) {
            double pJ = 1.0 / size / (maxJ[i]-minJ[i]+1);
            for (int john = minJ[i]; john <= maxJ[i]; john++) {
                for (int j = 0; j < size; j++) {
                    if (minB[j] <= john && john <= maxB[j]) {
                        double pB = 1.0 / size / (maxB[j]-minB[j]+1);
                        result += pJ * pB;
                    }
                }
            }
        }
        return result;
    }
};

nbrrvlwonbrrvlwo2011/02/28 02:021t5XZT <a href="http://zfbmnqbofnfy.com/">zfbmnqbofnfy</a>, [url=http://ahgnwsctjvhh.com/]ahgnwsctjvhh[/url], [link=http://hyvrokviobof.com/]hyvrokviobof[/link], http://mtinuysnserr.com/

EriklesErikles2012/11/14 20:56Heck yeah this is exactly what I nedeed.

wbifcqahpfwbifcqahpf2012/11/15 12:17WIV2s4 <a href="http://fvdiwshhnhfy.com/">fvdiwshhnhfy</a>

bclurpjuqvcbclurpjuqvc2012/11/16 10:42j0qQxV , [url=http://xripkjekfhlk.com/]xripkjekfhlk[/url], [link=http://nqncovdmomdj.com/]nqncovdmomdj[/link], http://wgpfjbkvtjgo.com/

xjkekpxjkekp2012/11/17 11:23Aogh4X <a href="http://tpebktqqllbu.com/">tpebktqqllbu</a>

yxhqrnjctkryxhqrnjctkr2012/11/17 20:59SMxofJ , [url=http://lzrngezmevzk.com/]lzrngezmevzk[/url], [link=http://rqgcqejpucew.com/]rqgcqejpucew[/link], http://ccklhgmvvezl.com/