ZOJ3827——Information Entropy

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3827

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*<br>输出用f<br>*/<br>/************************************************
* Author        :Powatr
* Created Time  :2015-8-18 10:37:09
* File Name     :ZOJ2827.cpp
 ************************************************/
 
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;
 
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 100 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
 
int main(){
    int n; char s[10];
    int a[MAXN];
    int T;
    scanf("%d", &T);
    while(T--){
    double ans = 0.0;
        scanf("%d%s", &n, s);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        for(int i = 1; i <= n; i++){
            if(a[i] == 0) continue;
           double res = (double)(1.0*a[i]*(1.0*log(1.0*a[i]/100))/100);
            if(s[0] == 'b')
                res = (double)res/(1.0*log(2.0));
            if(s[0] == 'd')
                res = (double)res/(1.0*log(10.0));
            ans += res;
        }
        printf("%.10f\n", -1.0*ans);
    }
    return 0;
}

  

posted @   Painting、时光  阅读(150)  评论(0编辑  收藏  举报
编辑推荐:
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
阅读排行:
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法
点击右上角即可分享
微信分享提示