我是靠谱客的博主 威武斑马,这篇文章主要介绍hdu/hdoj 1053 Entropy,现在分享给大家,希望可以做个参考。

题目大意:给你一个字符串,每一个字符在计算机中用8位编码表示,所以给你字符串AAAAABCD,它在计算机中要占用64位,可是为了节省内存,希望你能
设计出一种编码,使得内存的占用尽可能的少,即字符串的位数表示最少,输出  原本占几位,编码后占几位,二者的商

 

 

复制代码
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream> #include <queue> #include <vector> #include <stdio.h> #include <string> #include <cstring> using namespace std; struct kiss { int kk; bool operator < (const kiss &a) { return kk>a.kk; } }tmep[27]; priority_queue<int,vector<int>,greater<int> > que; int main() { string str; while (getline(cin,str),str!="END") { for (int i=0; i<27; ++i) { tmep[i].kk=0; } while(!que.empty()) que.pop(); for (int i=0; i<str.length(); ++i) { if (str[i]=='_') tmep[26].kk++; else tmep[str[i]-'A'].kk++; } for (int i=0; i<27; ++i) { if (tmep[i].kk!=0) { que.push(tmep[i].kk); } } int ans=0,a,b; if (que.size()==1) { que.pop(); printf("%d %d 8.0n",str.length()*8,str.length()); } else { while(que.size()!=1) { a=que.top();que.pop(); b=que.top();que.pop(); que.push(a+b); ans+=(a+b); } printf("%d %d %.1lfn",str.length()*8,ans,str.length()*8.0/ans); } } }


用优先队列实现,方便的很,可能需要注意只有1个字母的情况

 

 

最后

以上就是威武斑马最近收集整理的关于hdu/hdoj 1053 Entropy的全部内容,更多相关hdu/hdoj内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(129)

评论列表共有 0 条评论

立即
投稿
返回
顶部