HDU - 5419 Victor and Toys(组合计数)
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
- #include<iostream>
- #include<cmath>
- #include<cstring>
- #include<queue>
- #include<vector>
- #include<cstdio>
- #include<algorithm>
- #include<map>
- #include<set>
- #define rep(i,e) for(int i=0;i<(e);i++)
- #define rep1(i,e) for(int i=1;i<=(e);i++)
- #define repx(i,x,e) for(int i=(x);i<=(e);i++)
- #define X first
- #define Y second
- #define PB push_back
- #define MP make_pair
- #define mset(var,val) memset(var,val,sizeof(var))
- #define scd(a) scanf("%d",&a)
- #define scdd(a,b) scanf("%d%d",&a,&b)
- #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
- #define pd(a) printf("%d\n",a)
- #define scl(a) scanf("%lld",&a)
- #define scll(a,b) scanf("%lld%lld",&a,&b)
- #define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
- #define IOS ios::sync_with_stdio(false);cin.tie(0)
- using namespace std;
- typedef long long ll;
- template <class T>
- void test(T a){cout<<a<<endl;}
- template <class T,class T2>
- void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
- template <class T,class T2,class T3>
- void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
- const int N = 1e6+;
- //const int MAXN = 210;
- const int inf = 0x3f3f3f3f;
- const ll INF = 0x3f3f3f3f3f3f3f3fll;
- const ll mod = ;
- int T;
- void testcase(){
- printf("Case #%d: ",++T);
- }
- const int MAXN = 1e5+;
- const int MAXM = ;
- ll gcd(ll a,ll b){
- return b==?a:gcd(b,a%b);
- }
- ll C(ll n){
- return n*(n-)*(n-)/;
- }
- int qu[MAXN],w[MAXN];
- int main() {
- #ifdef LOCAL
- freopen("in.txt","r",stdin);
- #endif // LOCAL
- int t,n,m,l,r;
- scd(t);
- while(t--){
- mset(qu,);
- scdd(n,m);
- for(int i=;i<=n;i++) scd(w[i]);
- for(int i=;i<m;i++){
- scdd(l,r);
- qu[l]++,qu[r+]--;
- }
- ll fenzi=;
- int cnt=;
- for(int i=;i<=n;i++){
- cnt+=qu[i];
- if(cnt>=) fenzi+=(w[i]*C(cnt));
- }
- ll fenmu=C(m);
- if(fenzi==||fenmu==){
- puts("");
- continue;
- }
- ll d=gcd(fenmu,fenzi);
- if(d>){
- fenzi/=d;
- fenmu/=d;
- }
- cout<<fenzi;
- if(fenmu==) cout<<endl;
- else cout<<"/"<<fenmu<<endl;
- }
- return ;
- }
HDU - 5419 Victor and Toys(组合计数)的更多相关文章
- HDU 5419——Victor and Toys——————【线段树|差分前缀和】
Victor and Toys Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others ...
- HDOJ 5419 Victor and Toys 树状数组
分母是一定的C(m,3) 树状数组求每一个数能够在那些段中出现,若x出如今了s段中,分子加上w[x]*C(s,3) Victor and Toys Time Limit: 2000/1000 MS ( ...
- HDU.4903.The only survival(组合 计数)
题目链接 惊了 \(Description\) 给定\(n,k,L\),表示,有一张\(n\)个点的无向完全图,每条边的边权在\([1,L]\)之间.求有多少张无向完全图满足,\(1\)到\(n\)的 ...
- 【HDOJ 5419】 Victor and Toys (排列组合)
[HDOJ 5419] Victor and Toys n个玩具 m个区间 每一个玩具有一个beauty值 问任选三个区间 三区间的MINleft~MAXright的和的期望值 预处理一个数组 存放每 ...
- HDU4609 FFT+组合计数
HDU4609 FFT+组合计数 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意: 找出n根木棍中取出三根木棍可以组成三角形的概率 题解: ...
- ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩
HDU 5418 Victor and World Time Limit:2000MS Memory Limit:131072KB 64bit IO Format:%I64d & ...
- bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)
黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...
- 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是第二类斯特林 ...
- 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是第二类斯特林 ...
随机推荐
- XMLHttpRequest详解
XMLHttpRequest详解: https://xhr.spec.whatwg.org/
- ubuntu软件安装位置
有时候需要配置ubuntu安装的软件,一般安装软件都是使用apt-get install.那么安装完后,软件的安装目录在哪里呢,可执行文件又放在哪里呢. A.下载的软件的存放位置:/var/cache ...
- 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 ...
- C-Lodop的https扩展版,火狐下添加例外
LODOP综合版里的c-lodop是标准版,没有https和广域网打印功能,如果使用了标准版,调试JS的时候会提示,,loaded over HTTPS,,,the content must be s ...
- Async和Await 异步方法
Async和Await关键字是C#异步编程的核心.通过使用这两个关键字,你可以使用.NET Framework或Windows Runtime的资源创建一个异步方法如同你创建一个同步的方法一样容易.通 ...
- 一本通1585【例 1】Amount of Degrees
1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...
- jenkins--svn基本使用
新建项目 源码管理 #选择svn配置 svn基本信息配置 其中包括: Repository URL: svn://10.101.0.XXX:9507/XXXX Credentials: 配置你的 ...
- jsp操作MySQL时报错:Operation not allowed after ResultSet closed
一个stmt对多个rs进行操作引起的ResultSet关闭的错误 解决办法:创建新的stmt,一个rs对应一个stmt
- 沉迷Link-Cut tree无法自拔之:[BZOJ2594][Wc2006]水管局长数据加强版
来自蒟蒻 \(Hero \_of \_Someone\) 的 \(LCT\) 学习笔记 $ $ 这应该算是道套路题吧, 如果将图中的边转换成点, 再将边权变点权, 就可以用 \(LCT\) 来维护了 ...
- 【codeforces 175D】 Plane of Tanks: Duel
http://codeforces.com/problemset/problem/175/D (题目链接) 题意 A,B两人玩坦克大战,坦克有生命值,射击间隔,伤害范围,未命中的概率.问A赢的概率是多 ...