http://acm.hdu.edu.cn/showproblem.php?pid=5419

题意

n个物品,标号1-n,物品i有权值wi。现在有m个区间[l,r],从中任意选三个区间i,j,k,求物品编号在区间[ max{li,lj,lk},min{ri,rj,rk} ]的权值和,问总期望是多少。

分析

选择区间的总情况数为C(m,3)=m*(m-1)*(m-2)/6。对于物品,其存在贡献的地方一定是包含它的区间,那么先求出包含每个物品的区间数,用区间覆盖的思想,假设有num个区间包含权值为w的物品,那么此时它的总贡献就是w*C(num,3),只有三个都包含的同时选到才有效。注意使用long long

  1. #include<iostream>
  2. #include<cmath>
  3. #include<cstring>
  4. #include<queue>
  5. #include<vector>
  6. #include<cstdio>
  7. #include<algorithm>
  8. #include<map>
  9. #include<set>
  10. #define rep(i,e) for(int i=0;i<(e);i++)
  11. #define rep1(i,e) for(int i=1;i<=(e);i++)
  12. #define repx(i,x,e) for(int i=(x);i<=(e);i++)
  13. #define X first
  14. #define Y second
  15. #define PB push_back
  16. #define MP make_pair
  17. #define mset(var,val) memset(var,val,sizeof(var))
  18. #define scd(a) scanf("%d",&a)
  19. #define scdd(a,b) scanf("%d%d",&a,&b)
  20. #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
  21. #define pd(a) printf("%d\n",a)
  22. #define scl(a) scanf("%lld",&a)
  23. #define scll(a,b) scanf("%lld%lld",&a,&b)
  24. #define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
  25. #define IOS ios::sync_with_stdio(false);cin.tie(0)
  26.  
  27. using namespace std;
  28. typedef long long ll;
  29. template <class T>
  30. void test(T a){cout<<a<<endl;}
  31. template <class T,class T2>
  32. void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
  33. template <class T,class T2,class T3>
  34. void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
  35. const int N = 1e6+;
  36. //const int MAXN = 210;
  37. const int inf = 0x3f3f3f3f;
  38. const ll INF = 0x3f3f3f3f3f3f3f3fll;
  39. const ll mod = ;
  40. int T;
  41. void testcase(){
  42. printf("Case #%d: ",++T);
  43. }
  44. const int MAXN = 1e5+;
  45. const int MAXM = ;
  46.  
  47. ll gcd(ll a,ll b){
  48. return b==?a:gcd(b,a%b);
  49. }
  50. ll C(ll n){
  51. return n*(n-)*(n-)/;
  52. }
  53. int qu[MAXN],w[MAXN];
  54. int main() {
  55. #ifdef LOCAL
  56. freopen("in.txt","r",stdin);
  57. #endif // LOCAL
  58. int t,n,m,l,r;
  59. scd(t);
  60. while(t--){
  61. mset(qu,);
  62. scdd(n,m);
  63. for(int i=;i<=n;i++) scd(w[i]);
  64. for(int i=;i<m;i++){
  65. scdd(l,r);
  66. qu[l]++,qu[r+]--;
  67. }
  68. ll fenzi=;
  69. int cnt=;
  70. for(int i=;i<=n;i++){
  71. cnt+=qu[i];
  72. if(cnt>=) fenzi+=(w[i]*C(cnt));
  73. }
  74. ll fenmu=C(m);
  75.  
  76. if(fenzi==||fenmu==){
  77. puts("");
  78. continue;
  79. }
  80. ll d=gcd(fenmu,fenzi);
  81. if(d>){
  82. fenzi/=d;
  83. fenmu/=d;
  84.  
  85. }
  86. cout<<fenzi;
  87. if(fenmu==) cout<<endl;
  88. else cout<<"/"<<fenmu<<endl;
  89. }
  90. return ;
  91. }

HDU - 5419 Victor and Toys(组合计数)的更多相关文章

  1. HDU 5419——Victor and Toys——————【线段树|差分前缀和】

    Victor and Toys Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others ...

  2. HDOJ 5419 Victor and Toys 树状数组

    分母是一定的C(m,3) 树状数组求每一个数能够在那些段中出现,若x出如今了s段中,分子加上w[x]*C(s,3) Victor and Toys Time Limit: 2000/1000 MS ( ...

  3. HDU.4903.The only survival(组合 计数)

    题目链接 惊了 \(Description\) 给定\(n,k,L\),表示,有一张\(n\)个点的无向完全图,每条边的边权在\([1,L]\)之间.求有多少张无向完全图满足,\(1\)到\(n\)的 ...

  4. 【HDOJ 5419】 Victor and Toys (排列组合)

    [HDOJ 5419] Victor and Toys n个玩具 m个区间 每一个玩具有一个beauty值 问任选三个区间 三区间的MINleft~MAXright的和的期望值 预处理一个数组 存放每 ...

  5. HDU4609 FFT+组合计数

    HDU4609 FFT+组合计数 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意: 找出n根木棍中取出三根木棍可以组成三角形的概率 题解: ...

  6. ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩

    HDU 5418 Victor and World Time Limit:2000MS     Memory Limit:131072KB     64bit IO Format:%I64d & ...

  7. bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)

    黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...

  8. BZOJ 4555: [Tjoi2016&Heoi2016]求和 [分治FFT 组合计数 | 多项式求逆]

    4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...

  9. BZOJ 4555: [Tjoi2016&Heoi2016]求和 [FFT 组合计数 容斥原理]

    4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...

随机推荐

  1. XMLHttpRequest详解

    XMLHttpRequest详解: https://xhr.spec.whatwg.org/

  2. ubuntu软件安装位置

    有时候需要配置ubuntu安装的软件,一般安装软件都是使用apt-get install.那么安装完后,软件的安装目录在哪里呢,可执行文件又放在哪里呢. A.下载的软件的存放位置:/var/cache ...

  3. scipy线性模块liner(linalg)

    #liner import numpy as np from scipy import linalg as lg arr=np.array([[1,1],[0,1]]) matr=np.mat('[1 ...

  4. C-Lodop的https扩展版,火狐下添加例外

    LODOP综合版里的c-lodop是标准版,没有https和广域网打印功能,如果使用了标准版,调试JS的时候会提示,,loaded over HTTPS,,,the content must be s ...

  5. Async和Await 异步方法

    Async和Await关键字是C#异步编程的核心.通过使用这两个关键字,你可以使用.NET Framework或Windows Runtime的资源创建一个异步方法如同你创建一个同步的方法一样容易.通 ...

  6. 一本通1585【例 1】Amount of Degrees

    1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...

  7. jenkins--svn基本使用

    新建项目 源码管理  #选择svn配置 svn基本信息配置 其中包括: Repository URL:  svn://10.101.0.XXX:9507/XXXX Credentials:  配置你的 ...

  8. jsp操作MySQL时报错:Operation not allowed after ResultSet closed

    一个stmt对多个rs进行操作引起的ResultSet关闭的错误 解决办法:创建新的stmt,一个rs对应一个stmt

  9. 沉迷Link-Cut tree无法自拔之:[BZOJ2594][Wc2006]水管局长数据加强版

    来自蒟蒻 \(Hero \_of \_Someone\) 的 \(LCT\) 学习笔记 $ $ 这应该算是道套路题吧, 如果将图中的边转换成点, 再将边权变点权, 就可以用 \(LCT\) 来维护了 ...

  10. 【codeforces 175D】 Plane of Tanks: Duel

    http://codeforces.com/problemset/problem/175/D (题目链接) 题意 A,B两人玩坦克大战,坦克有生命值,射击间隔,伤害范围,未命中的概率.问A赢的概率是多 ...