zoukankan      html  css  js  c++  java
  • ZOJ 3827 Information Entropy (2014牡丹江区域赛)

    题目链接:ZOJ 3827 Information Entropy

    依据题目的公式算吧,那个极限是0



    AC代码:

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    const double e=exp(1.0);
    double find(char op[])
    {
        if(op[0]=='b')
            return 2.0;
        else if(op[0]=='n')
            return e;
        else if(op[0]=='d')
            return 10.0;
    }
    int main()
    {
        int t,i,n;
        double p[210],b;
        char op[20];
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d %s",&n,op);
            b=find(op);
            double ans=0.0;
            for(i=0;i<n;i++)
            {
                scanf("%lf",&p[i]);
                p[i]/=100.0;
    			if(p[i]!=0.0)
    				ans+=p[i]*log(p[i])/log(b);
            }
            printf("%.12lf
    ",-ans);
        }
    return 0;
    }
    




  • 相关阅读:
    ARC 080
    CodeForces
    [Lydsy1806月赛] 路径统计
    AGC 022 C
    AGC 022 B
    AGC 020 B
    UVA
    AGC 018 A
    python
    python
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/7284415.html
Copyright © 2011-2022 走看看