日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

ZOJ 3827 Information Entropy(数学题 牡丹江现场赛)

發(fā)布時間:2024/4/17 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ZOJ 3827 Information Entropy(数学题 牡丹江现场赛) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?

problemId=5381


Information Theory is one of the most popular courses in Marjar University. In this course, there is an important chapter about information entropy.

Entropy is the average amount of information contained in each message received. Here, a message stands for an event, or a sample or a character drawn from a distribution or a data stream. Entropy thus characterizes our uncertainty about our source of information. The source is also characterized by the probability distribution of the samples drawn from it. The idea here is that the less likely an event is, the more information it provides when it occurs.

Generally, "entropy" stands for "disorder" or uncertainty. The entropy we talk about here was introduced by Claude E. Shannon in his 1948 paper "A Mathematical Theory of Communication". We also call it Shannon entropy or information entropy to distinguish from other occurrences of the term, which appears in various parts of physics in different forms.

Named after Boltzmann's H-theorem, Shannon defined the entropy Η (Greek letter Η, η) of a discrete random variable?X?with possible values?{x1, x2, ..., xn}?and probability mass function?P(X)?as:

H(X)=E(?ln(P(x)))

Here E is the expected value operator. When taken from a finite sample, the entropy can explicitly be written as

H(X)=?i=1nP(xi)log?b(P(xi))

Where?b?is the base of the logarithm used. Common values of b are 2, Euler's number?e, and 10. The unit of entropy is?bit?for?b?= 2,?nat?for?b?=?e, and?dit?(or digit) for?b?= 10 respectively.

In the case of?P(xi)?= 0 for some?i, the value of the corresponding summand 0 logb(0) is taken to be a well-known limit:

0log?b(0)=limp0+plog?b(p)

Your task is to calculate the entropy of a finite sample with?N?values.

Input

There are multiple test cases. The first line of input contains an integer?T?indicating the number of test cases. For each test case:

The first line contains an integer?N?(1 <=?N?<= 100) and a string?S. The string?S?is one of "bit", "nat" or "dit", indicating the unit of entropy.

In the next line, there are?N?non-negative integers?P1,?P2, ..,?PN.?Pi?means the probability of the?i-th value in percentage and the sum of?Pi?will be 100.

Output

For each test case, output the entropy in the corresponding unit.

Any solution with a relative or absolute error of at most 10-8?will be accepted.

Sample Input

3 3 bit 25 25 50 7 nat 1 2 4 8 16 32 37 10 dit 10 10 10 10 10 10 10 10 10 10

Sample Output

1.500000000000 1.480810832465 1.000000000000
Author:?ZHOU, Yuchen


PS:2014年ACM/ICPC 亞洲區(qū)域賽牡丹江(第一站)現(xiàn)場賽


代碼例如以下:

#include<cstdio> #include<cmath> #include <cstring> const double e = exp(1.0); double judge(char s[]) {if(strcmp("bit",s) == 0)return 2.0;else if(strcmp("nat",s) == 0)return e;else if(strcmp("dit",s) == 0)return 10.0;} int main() {int t;int n;char s[7];double p[117];//printf("%lf\n",e);scanf("%d",&t);while(t--){scanf("%d",&n);scanf("%s",s);double b = judge(s);for(int i = 0; i < n; i++){scanf("%lf",&p[i]);p[i] /= 100.0;}double ans = 0;double tt = log(b);for(int i = 0; i < n; i++){if(p[i] != 0)ans+=p[i]*log(p[i])/tt;else if(p[i] == 0){ans+=0;}}ans = -ans;printf("%.12lf\n",ans);}return 0; }


轉(zhuǎn)載于:https://www.cnblogs.com/gccbuaa/p/6856836.html

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的ZOJ 3827 Information Entropy(数学题 牡丹江现场赛)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品ⅴa有声小说 | 理论片琪琪午夜电影 | 麻豆视频免费看 | 国产精品视频123 | 日本少妇影院 | 夜夜狠| 强睡邻居人妻中文字幕 | 理论片高清免费理伦片 | 亚洲精品天堂成人片av在线播放 | 自拍欧美日韩 | 久操视频免费在线观看 | 久久av秘一区二区三区 | 你懂的91| 中文字幕Av日韩精品 | 九九自拍 | 久久伊人久久 | 久久一级大片 | ,午夜性刺激免费看视频 | 91国内精品| 亚洲女同志亚洲女同女播放 | 秋霞99| 日韩毛片一级 | 久久精品小视频 | 色姐| 99久久婷婷国产一区二区三区 | 国内成人av | 女性向片在线观看 | 日日舔夜夜操 | 亚洲乱码国产乱码精品精的特点 | 国产成人精品免费视频 | 成年人午夜 | 一区二区三区午夜 | 欧美日韩在线免费观看视频 | 国产日韩视频在线观看 | 欧美性吧 | 色资源在线 | 草草影院ccyycom | 国产一区精品在线 | 奇米第四色7777 | 特级西西www444人体聚色 | 日韩美女免费视频 | 操老女人视频 | 国产精品久久欧美久久一区 | 日韩一二三区在线观看 | 少妇一级淫片免费放中国 | 免费成人黄色av | 日日夜夜狠狠干 | 成人做爰www免费看视频网站 | 五月激情开心网 | 五月天婷婷久久 | 老牛影视一区二区三区 | 国产精品毛片一区视频播 | 成人tiktok黄短视频 | 亚洲精品福利 | 国产精品亚洲AV色欲三区不卡 | 国产中文 | 91成人免费视频 | 免费的a级片 | 成人在线国产视频 | 狠狠爱夜夜 | 国产精品丝袜黑色高跟鞋 | 公肉吊粗大爽色翁浪妇视频 | 国内一区二区 | 国产精品77 | 在线观看中文字幕2021 | 四虎永久免费观看 | 欧美黄色a| 无码任你躁久久久久久老妇 | 91精品一区二区三区综合在线爱 | 男人亚洲天堂 | 黄色免费视屏 | 青青草在线免费视频 | 怡红院一区二区三区 | 亚洲淫| 亚洲欧美伦理 | av网址网站 | 国产普通话bbwbbwbbw | 91在线免费看| 毛片在线免费观看视频 | 性猛交xxxx乱大交孕妇印度 | 欧美成人一区在线观看 | 日本黄色xxx| 69av一区二区三区 | 999精品视频在线观看 | 熟女高潮一区二区三区 | 久久成人综合网 | 欧洲成人午夜精品无码区久久 | 亚洲永久视频 | 欧美不卡影院 | 欧美另类videosbestsex日本 | 亚洲一区二区在线免费观看 | 欧美群交射精内射颜射潮喷 | 性高跟丝袜xxxxhd | 黄色小视频在线播放 | 不卡av网 | 懂色一区二区三区免费观看 | 欧美色图五月天 | 小镇姑娘国语版在线观看免费 | 国产av无码专区亚洲av毛网站 |