题意:
给出一个长度为n的二进制数x和一个长度为(1<<n)的数组C,一开始x的每一位都为-1,有两位玩家A和B,每轮随机选出一名玩家将x中的一个-1改为0或1(由玩家决定),在x确定之后游戏的结果为C[x],玩家A想让C[x]大,玩家B想让C[x]尽量小,求C[x]的期望,此外,还会有r次更改,每次修改C数组的某个值,对于每次修改也求出C[x]的期望
分析:
对于二进制位的每一位来说,对于每一个二进制位,玩家A和玩家B的设置必然相反,又由于随机抽取玩家,所以每一位是0或1的概率相同,所以只需要对C数组求和除以C数组长度即是答案
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define mk make_pair
#define sc(x) scanf("%d", &x)
#define pb push_back
#define debug puts("???")
#define ABS(x) ((x)<0?(-x):(x));
typedef long long LL;
using namespace std;
const int mod = 998244353;
const int maxn = 1e6+10;
int n, r, c[maxn];
int main(){
sc(n); sc(r);
n = (1<<n);
LL sum = 0;
for(int i = 0; i < n; i++){
sc(c[i]);
sum += c[i];
}
printf("%.7f\n", sum*1.0/n);
while(r--){
int x, y;
sc(x); sc(y);
sum -= c[x];
sum += y;
c[x] = y;
printf("%.7f\n", sum*1.0/n);
}
return 0;
}