uva 10288 Coupons 数学期望
来源:互联网 发布:sjcam sj5000x淘宝 编辑:程序博客网 时间:2024/06/13 23:42
- 计算期望可以从两个角度出发计算概率,第一个角度是直接计算,第二个角度是计算每增加一个的概率。
- 1+s+s^2+s^3+…+s^n n–>无穷,由等比数列前n项和公式为a1*(1-q^n)/(1-q);
q是分数,n是无穷,所以为1/(1-q) - 1+2p+3p^2+….np^(n-1),这个式子有两个特征,系数是递进的,抛开系数像是一个等比数列,那么我通过构造错位就可以构造出一个真正的等比数列。设这个式子为E,那么E-p*E就是一个等差数列了。
题目链接:http://ln1.vjudge.net/problem/481
#include<cstdio>#include<iostream>#include<sstream>#include<cstdlib>#include<cmath>#include<cctype>#include<string>#include<cstring>#include<algorithm>#include<stack>#include<queue>#include<set>#include<map>#include<ctime>#include<vector>#include<fstream>#include<list>using namespace std;#define ms(s) memset(s,0,sizeof(s))typedef unsigned long long ULL;typedef long long LL;const int INF = 0x3fffffff;LL gcd(LL a, LL b){ return (b==0) ? a : gcd(b,a%b);}LL lcm(LL a, LL b){ return a / gcd(a,b) * b;}int main(){// freopen("F:\\input.txt","r",stdin);// freopen("F:\\output.txt","w",stdout);// ios::sync_with_stdio(false); LL lcmm[35]; ms(lcmm); lcmm[1] = 1; for(int i = 2; i <= 33; ++i){ lcmm[i] = lcm(lcmm[i-1],i); } int n; int w1,w2; double ans; LL a,b; LL gcdd; LL ans1; while(~scanf("%d",&n)){ if(n==1) printf("1\n"); else if(n==2) printf("3\n"); else{ a = 0; for(int i = 1; i <= n; ++i){ a += lcmm[n]/i; } a = a*n; b = lcmm[n]; ans1 = a/b; a = a%b; gcdd = gcd(a,b); a /= gcdd; b /= gcdd; w1 = log10(ans1)+1; w2 = log10(b)+1; for(int i = 0; i < w1; ++i) printf(" "); printf(" %lld\n",a); printf("%lld ",ans1); for(int i = 0; i < w2; ++i) printf("-"); printf("\n"); for(int i = 0; i < w1; ++i) printf(" "); printf(" %lld\n",b); } } return 0;}
1 0
- uva 10288 Coupons 数学期望
- UVA 10288 Coupons 数学期望
- uva 10288 Coupons 数学期望,分数计算表示
- 10288 - Coupons (数学期望)
- [UVA10288] Coupons && 数学期望
- UVA 题目10288 Coupons(期望)
- UVa 10288(Coupons) 数学期望(概率+递推) Java
- Uva 10288 - Coupons
- UVA 10288 - Coupons
- uva 10288 coupons
- UVA 10288 Coupons
- uva 10288 - Coupons(概率)
- UVA 10288 - Coupons
- UVa 10288 Coupons
- UVA 10288(p333)----Coupons
- uva 10288 Coupons
- uva 10288 Coupons
- Uva 10288 Coupons
- tcp短连接TIME_WAIT问题解决方法
- 最优子结构(optimal substructure)
- 安卓强大的Fragment管理器
- gulp + webpack 构建多页面前端项目
- 基于 webpack 搭建前端工程基础篇
- uva 10288 Coupons 数学期望
- codeforces 706D (字典树)
- objc/runtime中SEL、IMP和method动态定义
- [React项目总结] 基于 webpack 搭建前端工程基础篇
- 在多个Android项目工程中共享一个库模块
- webpack & react项目搭建一:环境
- android数据存储之文件存储
- QFtp多路并发传输崩溃的问题
- 动态规划问题系列---连续子数组(二维)的最大和