BestCoder#52 Victor and Toys
来源:互联网 发布:开80端口 编辑:程序博客网 时间:2024/05/18 02:47
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5419
分析:分母是C(m,3)。首先题意:三个区间的交集会对分子有贡献,即三个区间都包含元素a则a对分子有贡献。用差分前缀和预处理被几个区间覆盖,第i个对分子的贡献即wi*C(num[i],3)。注意各个变量是int还是longlong,坑死了。
代码:
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int Tmax=50005;int n,m,w[Tmax],num[Tmax];long long int p,q;long long int gcd(long long int a,long long int b){ return b==0?a:gcd(b,a%b);}void work(){ int i,tmp=0; long long int Tgcd; q=(long long int)1*m*(m-1)*(m-2)/6;p=0; for(i=1;i<=n;i++) { tmp+=num[i]; p+=(long long int)1*w[i]*tmp*(tmp-1)*(tmp-2)/6; } if(p==0||q==0){ printf("0\n"); return; } Tgcd=gcd(p,q); p/=Tgcd;q/=Tgcd; if(q==1) printf("%lld\n",p); else printf("%lld/%lld\n",p,q); return;}int main(){ int T,i,l,r; scanf("%d",&T); while(T--) { scanf("%d %d",&n,&m); for(i=1;i<=n;i++) scanf("%d",&w[i]),num[i]=0; for(i=1;i<=m;i++) { scanf("%d %d",&l,&r); num[l]++; num[r+1]--; } work(); } return 0;}
0 0
- BestCoder#52 Victor and Toys
- BestCoder#52 Victor and World
- 【hdu5419】Victor and Toys
- hdu 5419 Victor and Toys
- HDU 5419 Victor and Toys
- 【HDOJ 5419】 Victor and Toys (排列组合)
- HDOJ 5419 Victor and Toys 树状数组
- hdu5419--Victor and Toys(枚举)
- HDU 5419 Victor and Toys ()
- BestCoder Round #52 (div.2) 1001 Victor and Machine
- BestCoder Round #52 (div.2) Victor and Machine
- Victor and Machine----(BestCoder Round #52 (div.2))
- BestCoder Round #52 (div.2)HDU5417 Victor and Machine
- hdu 5419 Victor and Toys 线段树成段更新
- hdu5419 Victor and Toys 期望,差分前缀和
- hdu 5419 Victor and Toys(暴力+组合)
- HDU 5417 Victor and Machine——BestCoder Round #52(div.2)
- BestCoder Round #52 (div.2) HDU 5418 Victor and World (DP+状态压缩)
- 解决Ubuntu系统中文乱码显示问题
- 从dll得到lib文件
- 黑马程序员-----正则表达式
- constexpr和常量表达式
- Cannot set TextView width using setWidth or setLayoutParams
- BestCoder#52 Victor and Toys
- eclipse集成jboss及jboss环境配置
- Ubuntu安装vncserver实现图形化访问
- oracle函数trunc的使用
- MS sql 小技巧
- linux vnc服务配置详细教程
- C# interface 接口理解
- SPOJ VLATTICE Visible Lattice Points (莫比乌斯反演基础题)
- 运行hadoop程序遇到的一些问题及解决方案