zoj 3827 Information Entropy(水题)
2014-10-13 09:29
381 查看
题目链接:zoj 3827 Information Entropy
题目大意:三种底,计算和。
解题思路:调用库函数就可以直接算了,不过要注意Pi = 0的时候,不过它题目里居然也讲了。。。limp→0+plogb(p)=0,因为p是logp的高阶。
题目大意:三种底,计算和。
解题思路:调用库函数就可以直接算了,不过要注意Pi = 0的时候,不过它题目里居然也讲了。。。limp→0+plogb(p)=0,因为p是logp的高阶。
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int N; double f(double x, int k) { if (x == 0) return 0; if (k == 1) return x * log2(x); else if (k == 2) return x * log(x); else return x * log10(x); } int main () { int cas, k; scanf("%d", &cas); while (cas--) { char op[10]; scanf("%d%s", &N, op); if (op[0] == 'b') k = 1; else if (op[0] == 'n') k = 2; else if (op[0] == 'd') k = 3; int x; double ans = 0; for (int i = 1; i <= N; i++) { scanf("%d", &x); ans += f(x / 100.0, k); } printf("%.8lf\n", -ans); } return 0; }
相关文章推荐
- zoj 3827(水题)
- zoj 3827 Information Entropy 【水题】
- ZOJ 3827 Information Entropy【水题、简单相加】
- ZOJ 3827 Information Entropy 水题
- [ZOJ]1048-水题一枚-注意数据类型转换的技巧
- J - What day is that day?(zoj水题)
- ZOJ 1586 QS Network 最小生成树水题
- ZOJ 3210 A Stack or A Queue? 水题
- ZOJ 17届校赛 Knuth-Morris-Pratt Algorithm( 水题)
- zoj 1041 水题
- POJ2247 HDU1058 UVA443 ZOJ1095 Humble Numbers【数学计算+打表+水题】
- UVALive2953 POJ1775 ZOJ2358 Sum of Factorials【打表+暴力+水题】
- ZOJ 3819 Average Score【水题】
- ZOJ 2165 POJ 1979 Red and Black DFS水题
- zoj--3932--Handshakes(水题)
- zoj 2857 Image Transformation水题
- zoj 1331 Perfect Cubes(水题)
- ZOJ水题分类
- [ACM_水题] ZOJ 3712 [Hard to Play 300 100 50 最大最小]
- [水题+dfs] zoj 3861 Valid Pattern Lock