https://vjudge.net/contest/237352#problem/G
题意:有n个玩具,编号为1到n,其中编号为i的玩具价值为wi。有m个区间,其中第i个区间为[li,ri],随机选取了3个互不相同的数i,j,k(1≤i<j<k≤m),将所有足 max(li,lj,lk)≤x≤min(ri,rj,rk)的编号为x的玩具取出,求取出的玩具的有价值之和的期望是多少。
解法:考虑每一个点,对结果的影响,如果一个点包括了x个区间,那么,就有C(x,3)个w[i]在分子上,分母为C(m,3);所以最终的问题就是要求每个点所在的区间数,用区间标记的方法实现。注意不要爆long long。
注意判断判断结果为整数,分数,以及0的情况。
1 //#include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include