uva 10288 Coupons 数学期望

  1. 计算期望可以从两个角度出发计算概率,第一个角度是直接计算,第二个角度是计算每增加一个的概率。
  2. 1+s+s^2+s^3+…+s^n n–>无穷,由等比数列前n项和公式为a1*(1-q^n)/(1-q);
    q是分数,n是无穷,所以为1/(1-q)
  3. 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值