LightOJ 1342 Aladdin and the Magical Sticks expectations (conclusion title)

Topic Portal

  The meaning of problems: n stick, each stick has a weight, with a wooden stick and recognizable unrecognizable stick, stick every sampling, the weights will be accumulated, if the stick is identifiable not back, unrecognized stick on back, ask each stick at least once drawn the probability is.

  Ideas: Thesis?

    Class 1 stick only to pick up again, ans + = weight

    Class 2 will pick up several sticks, ans + = weight * h [n] h [n] is the Euler function item n

  Brought you a proof of the blog

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,b,a) for(int i=b;i>=a;i--)
#define clr(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pii pair<int,int >
using namespace std;
typedef long long ll;
ll rd() {
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
const int maxn=5000+10;
double f[maxn];
int main(){
    int T,cat=1;
    for(int i=1;i<=5000;i++){
        f[i]=f[i-1]+1.0/i;
    }
    cin>>T;
    while(T--){
        int n;
        double ans=0;
        cin>>n;
        rep (i, 1 , n) {
             int a, you;
            cin>>w>>ty;
            if(ty==1){
                ans+=w;
            }else{
                years + = w * f [n];
            }
        }
        printf("Case %d: %.7f\n",cat++,ans);
    }
}

 

Guess you like

Origin www.cnblogs.com/mountaink/p/11354652.html