ZOJ ——3827 Information Entropy
来源:互联网 发布:线切割制图软件 编辑:程序博客网 时间:2024/05/22 17:50
题意:题目给出一个求熵公式:然后编写程序实现该公式运算。
解题思路:本题关键点是所给的Pi值为所有Pi之和的百分比,故要得到公式中的p(x),还需进行Pi/100的运算。然后可按照公式进行编写,注意:在遇到0的时候,不进行处理,因为0*log(p0) = 0;此外还要注意c语言中log函数的运用。
Code:
#include <iostream>#include <cmath>#include <cstdio>using namespace std;int array[110];int main(){ //freopen("input.txt","r",stdin); int T,N; scanf("%d",&T); while(T--) { char S[5]; scanf("%d %s",&N,&S); for(int i = 0; i < N; i++) scanf("%d",&array[i]); double ans = 0; if(S[0] == 'b') { for(int i = 0; i < N; i++) { if(!array[i]) continue; ans +=(1.0*array[i]/100)*log2(array[i]*1.0/100); } } if(S[0] == 'n') { for(int i = 0; i < N; i++) { if(!array[i]) continue; ans +=(1.0*array[i]/100)*log(array[i]*1.0/100); } } if(S[0] == 'd') { for(int i = 0; i < N; i++) { if(!array[i]) continue; ans +=(1.0*array[i]/100)*log10(array[i]*1.0/100); } } printf("%.12lf\n",-ans); } return 0;}
0 0
- ZOJ ——3827 Information Entropy
- ZOJ 3827 Information Entropy
- ZOJ-3827-Information Entropy
- ZOJ 3827 Information Entropy
- ZOJ-3827-Information Entropy
- zoj 3827 Information Entropy(水题)
- ZOJ 3827 Information Entropy 水
- zoj 3827 Information Entropy 【水题】
- ZOJ Problem Set - 3827Information Entropy
- 解题报告 之 ZOJ 3827 Information Entropy
- ZOJ 3827 Information Entropy【水题、简单相加】
- ZOJ 3827 Information Entropy (2014牡丹江区域赛)
- ZOJ 3827 Information Entropy(数学题 牡丹江现场赛)
- 信息熵——Information Entropy
- zoj 3827 Information Entropy(2014牡丹江区域赛I题)
- 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-I ( ZOJ 3827 ) Information Entropy
- ZOJ 3630 —— Information
- 信息熵 information Entropy
- 新的起点,新的开始!
- 在使用viewPager做图片切换时注意图片存放的位置
- String类及其常用操作方法
- Kettle 5.x使用指南
- 三元组表压缩存储稀疏矩阵实现稀疏矩阵的快速转置(Java语言描述)
- ZOJ ——3827 Information Entropy
- 找工作--笔试面试--准备5
- ZOJ 3822 Domination The 2014 ACM-ICPC 牡丹江区域赛 概率dp 先算概率,再转成期望
- 魚有沼 虜皆羅拜
- Kinect for Windows V2和V1对比开发___骨骼数据获取并用OpenCV2.4.10显示
- 小组成员个人简介——钱珺
- [zoj 3822]2014牡丹江区域赛 Domination 概率dp求期望
- Java ME Embedded和Java Embedded Suite:嵌入式市场的新兴Java技术
- 三种方法编写的简单html界面(2)