其他分享
首页 > 其他分享> > Bzoj 2969 矩阵粉刷

Bzoj 2969 矩阵粉刷

作者:互联网

思想:期望,概率

#include <bits/stdc++.h>
using namespace std;

double P[1010][1010];
const double eps = 1E-9;
double quick_power(double a, int b)
{
    if (b == 0)
        return 1;
    double ans = quick_power(a, b >> 1);
    ans = ans * ans;
    if (b & 1)
        ans = ans * a;
    return ans;
}

int main()
{
    // cout << quick_power(0.5, 4) << endl;
    int w, h, k;
    cin >> k >> w >> h;
    for (int i = 1; i <= w; i ++)
        for (int j = 1; j <= h; j ++)
        {
            double p = (2. * i * (w - i + 1) - 1) * (2. * j * (h - j + 1) - 1) / (1. * w * h * w * h);
            // cout << p << endl;
            P[i][j] = 1 - quick_power(1 - p, k);
        }
    double ans = 0;
    for (int i = 1; i <= w; i ++)
        for (int j = 1; j <= h; j ++)
            ans += P[i][j];
    long long dd = round(ans);
    cout << dd << endl;
	// cout << ans << endl;
    return 0;
}


标签:return,cout,int,double,2969,粉刷,ans,1010,Bzoj
来源: https://blog.csdn.net/m0_61602619/article/details/120930654