首页 > 其他 > 详细

ZOJ 3827 Information Entropy (2014牡丹江区域赛)

时间:2017-08-04 13:35:29      阅读:175      评论:0      收藏:0      [点我收藏+]

题目链接: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\n",-ans);
    }
return 0;
}




ZOJ 3827 Information Entropy (2014牡丹江区域赛)

原文:http://www.cnblogs.com/yutingliuyl/p/7284415.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!