博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数学期望+区间标记
阅读量:4614 次
发布时间:2019-06-09

本文共 1883 字,大约阅读时间需要 6 分钟。

https://vjudge.net/contest/237352#problem/G

题意:有n个玩具,编号为1到n,其中编号为i的玩具价值为wi。有m个区间,其中第i个区间为[li,ri],随机选取了3个互不相同的数i,j,k(1i<j<km),将所有足 max(li,lj,lk)xmin(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
12 #include
13 #include
14 #include
15 #include
16 #define ms(a, b) memset(a, b, sizeof(a));17 using namespace std;18 typedef long long LL;19 typedef pair
pii;20 const int INF = 0x3f3f3f3f;21 const int maxn = 5e4 + 10;22 const int MAXN = 2e4 + 10;23 const double eps = 1e-8;24 const int mod = 1e9 + 7;25 int n, m;26 int w[maxn], f[maxn];27 28 LL C(LL k) {29 return k * (k-1) * (k-2) / 6;30 }31 32 LL gcd(LL a, LL b) {33 while(b) {34 LL tmp = a % b;35 a = b;36 b = tmp;37 }38 return a;39 }40 41 void solve() {42 43 return ;44 }45 46 47 int main() {48 #ifdef local49 freopen("case.in", "r", stdin);50 // freopen("case.out", "w", stdout);51 #endif52 // ios::sync_with_stdio(false);53 // cin.tie(0);54 int T;55 scanf("%d", &T);56 while(T--) {57 scanf("%d%d", &n, &m);58 for(int i = 1; i <= n; i++)59 scanf("%d", &w[i]);60 ms(f, 0);61 for(int i = 0; i < m; i++) {62 int l, r;63 scanf("%d%d", &l, &r);64 f[l]++;65 f[r+1]--;66 }67 LL cnt = 0, up = 0;68 for(int i = 1; i <= n; i++) {69 cnt += f[i];70 if(cnt >= 3) up += w[i] * C(cnt);71 }72 LL down = C(m);73 LL div = gcd(up, down);74 if(div > 0) {75 up /= div;76 down /= div;77 if(down == 1) printf("%lld\n", up);78 else printf("%lld/%lld\n", up, down);79 }80 else printf("0\n");81 }82 // solve();83 return 0;84 }

 

转载于:https://www.cnblogs.com/Sissi-hss/p/9440423.html

你可能感兴趣的文章
j2ee爬坑行之二 servlet
查看>>
JAVA基础入门(JDK、eclipse下载安装)
查看>>
最基础的applet运用--在applet上画线
查看>>
并不对劲的hdu4777
查看>>
linux使用rz、sz快速上传、下载文件
查看>>
判断数字的正则表达式
查看>>
DOC常用命令(转)
查看>>
php写一个判断是否有cookie的脚本
查看>>
Mac配置Fiddler抓包工具
查看>>
转:Java并发集合
查看>>
Word截图PNG,并压缩图片大小
查看>>
Python项目对接CAS方案
查看>>
mysql产生随机数
查看>>
编程风格
查看>>
熟悉常用的Linux命令
查看>>
易之 - 我是个大师(2014年3月6日)
查看>>
Delphi中窗体的事件
查看>>
file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did
查看>>
linux vi编辑器
查看>>
js树形结构-----(BST)二叉树增删查
查看>>