絶滅

どうでもいい

yukicoder - No.212

No.212 素数サイコロと合成数サイコロ (2)

問題ページ

各サイコロの出る目は独立なので積の期待値は期待値の積になる.

素数サイコロを 1 つ振って出る目の期待値 $\displaystyle E_p = \frac{41}{6}$

合成数サイコロを 1 つ振って出る目の期待値 $\displaystyle E_c = \frac{49}{6}$

より,求める期待値 $E$ は $E = (E_p)^{P} (E_c)^{C}. $

相対誤差 $10^{-9}$ なので printf が無難.

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;



//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr;    } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; } cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }    cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }    cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-6
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define all(x) (x).begin(), (x).end()




int yuki0212()
{
    int P, C;
    cin >> P >> C;

    double EP = 41.0 / 6, EC = 49.0 / 6, E = 1.0;

    for (int i = 0; i < P; i++) E *= EP;
    for (int i = 0; i < C; i++) E *= EC;

    printf("%.10f\n", E);

    return 0;
}

int main()
{
    //clock_t start, end;
    //start = clock();

    yuki0212();
    
    //end = clock();
    //printf("%d msec.\n", end - start);

    return 0;
}