zoj 3827(水题)

2 篇文章 0 订阅
/*
    zoj 3827
    题目大意就是
    根据题目给定的公式,然后算值就行


    题目很简单,可能看到给的式子有点吓人就是了
    只要注意
    三个字符串代表不同的底数
    题目中所给的p是概率,把输入进来的数除以100
    以及以2为底的对数可以写成以10(或者e)为底然后除以以10(或者e)2的对数就行
*/
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<stdio.h>
#include<math.h>
#define ll long long
#define PI acos(-1)
using namespace std;


int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        string b;
        cin>>n>>b;
        double h=0;
        if(b=="bit")
        {
            double p;
            for(int i=1; i<=n; i++)
            {
                cin>>p;
                if(p==0)
                    h=h+0;
                else
                    h=h+(p/100.0)*(log(p/100.0)/log(2.0));
            }
            h=-h;
        }
        else if(b=="nat")
        {
            double p;
            for(int i=1; i<=n; i++)
            {
                cin>>p;
                if(p==0)
                    h=h+0;
                else
                    h=h+(p/100.0)*(log(p/100.0));
            }
            h=-h;
        }
        else
        {
            double p;
            for(int i=1; i<=n; i++)
            {
                cin>>p;
                if(p==0)
                    h=h+0;
                else
                    h=h+(p/100.0)*(log10(p/100.0));
            }
            h=-h;
        }
        printf("%.12lf\n",h);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值