Entropy(哈弗曼编码,优先队列)
来源:互联网 发布:kali linux gnuradio 编辑:程序博客网 时间:2024/05/27 01:49
</pre><pre name="code" class="cpp">坑在只有一个字符的时候
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;#define maxn 1005#define inf 0x3f3f3f3fint main(){ char s[maxn]; int a[maxn]; freopen("in.txt","r",stdin); while(gets(s)){ if(!strcmp(s,"END"))break; int m=0; int sum=0; m=strlen(s); priority_queue<int>q; memset(a,0,sizeof a); for(int i=0;i<m;i++){ if(s[i]>='A'&&s[i]<='Z') a[s[i]-'A'+1]++; else a[0]++; } for(int i=0;i<=26;i++) if(a[i]>0)q.push(-a[i]); if(q.size()==1)sum+=-(q.top()); else{ while(q.size()>1){ int a=-q.top(); q.pop(); int b=-q.top(); q.pop(); sum+=a+b; q.push(-(a+b)); } } printf("%d %d %.1f\n",m*8,sum,1.0*m*8/sum); }}
0 0
- Entropy(哈弗曼编码,优先队列)
- Entropy(哈夫曼编码+优先队列)
- HDU 1053 Entropy 【优先队列+Huffman编码】
- poj 1521 Entropy(优先队列)
- poj 1521 Entropy 并查集+优先队列实现哈夫曼编码
- POJ 1521 Entropy 优先队列/multiset
- 哈夫曼编码(优先队列)
- poj 1521Entropy(哈弗曼编码)
- 赫夫曼编码(优先队列实现)
- HDU1053 Entropy(huffman编码)
- hdoj1053 Entropy(哈夫曼编码)
- 优先队列示例: 哈夫曼编码
- Huffman编码优先队列实现
- 优先队列实现 哈夫曼编码
- Entropy(有点队列使用)(哈夫曼)
- 1053 Entropy 哈弗曼编码 贪心算法
- POJ 1521 Entropy(哈夫曼编码)
- poj 1521 Entropy huffman(哈夫曼)编码
- win7/ubuntu双系统安装(安装ubuntu黑屏后光标一直闪)
- 439 - Knight Moves(bfs)
- android应用程序安装位置分析
- 第六周
- UINavigationController使用详解
- Entropy(哈弗曼编码,优先队列)
- Android项目优化查错神器之android lint
- 22 【健身】
- android获取应用程序的安装位置
- 主机win7,vbox虚拟机中ubuntu上网和共享文档随笔
- Context.getExternalFilesDir()和Context.getExternalCacheDir()方法
- 【2014,不经一番寒彻骨,怎得梅花扑鼻香】
- Lucene5 学习笔记(1) —— Hello World
- LeetCode:Department Highest Salary