博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
I - Information Entropy ZOJ - 3827 水
阅读量:4205 次
发布时间:2019-05-26

本文共 878 字,大约阅读时间需要 2 分钟。

题意:bit为2,nat为e,dit为10,求H(X)=i=1nP(xi)log b(P(xi))

题解:e取exp(1.0)即可,另外加上换底公式

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define lowbit(x) (x&-x)//ios::sync_with_stdio(false);typedef long long ll;typedef long long LL;using namespace std;#define e exp(1.0)int main(){ int T; ios::sync_with_stdio(false); cin>>T; int n; string s; while(T--) { double ans = 0; cin>>n>>s; double a; if(s=="bit")//2 { while(n--) { cin>>a; if(a==0) continue; a/=100.0; ans -= (a*log(a)/log(2.0)); } printf("%.10f\n",ans); //cout<
<
>a; if(a==0) continue; a/=100.0; ans -= (a*log(a)/log(e)); } printf("%.10f\n",ans); } else//10 { while(n--) { cin>>a; if(a==0) continue; a/=100.0; ans -= (a*log(a)/log(10.0)); } printf("%.10f\n",ans); } } return 0;}

转载地址:http://jlali.baihongyu.com/

你可能感兴趣的文章
magento url中 uenc 一坨编码 base64
查看>>
强大的jQuery焦点图无缝滚动走马灯特效插件cxScroll
查看>>
Yii2.0 数据库查询
查看>>
yii2 db 操作
查看>>
mongodb group 有条件的过滤组合个数。
查看>>
yii2 用命令行操作web下的controller
查看>>
yii2 console的使用
查看>>
关于mongodb的 数组分组 array group
查看>>
MongoDB新的数据统计框架介绍
查看>>
mongodb fulltextsearch 关于语言的设置选项
查看>>
mongodb 增加全文检索索引
查看>>
symfony
查看>>
yourls 短连接 安装
查看>>
yii2 php namespace 引入第三方非namespace库文件时候,报错:Class not found 的解决
查看>>
softlayer 端口开放
查看>>
操作1:mongodb安装
查看>>
操作2:mongodb使用语法
查看>>
如何给分类增加一个属性(后台)
查看>>
linux设置环境变量 临时设置 和 永久设置
查看>>
检查网站在世界各地的打开速度
查看>>