poj 1521
来源:互联网 发布:知乎 西游记原著版本 编辑:程序博客网 时间:2024/05/16 01:06
poj 1521 Entropy
#include <iostream>#include <queue>#include <string>#include <stdio.h>using namespace std;string s;int k=0;struct node{ int w; int parent; int key; friend bool operator < (const node & a,const node & b){ if(b.w<a.w)return true; else return false; } }alp[60];int value(char c){ if(c=='_')return 26; else return c-'A'; }void huf(){ int i,j; int length=s.length(); priority_queue<node>q; for(i=0;i<length;i++) alp[value(s[i])].w++; for(i=0;i<=26;i++){ if(alp[i].w!=0){ q.push(alp[i]); } } if(q.size()==1) printf("%d %d 8.0\n",8*length,length); else { j=27; while(q.size()>1){ node s1=q.top(); q.pop(); node s2=q.top(); q.pop(); alp[j].w=s1.w+s2.w; alp[s1.key].parent=j; alp[s2.key].parent=j; q.push(alp[j]); j++; } int res=0; for(int ii=0;ii<27;ii++){ if(alp[ii].w!=0){ int len=1; int par=alp[ii].parent; while(par!=j-1){ len++; par=alp[par].parent; } res+=len*alp[ii].w; } } double dd=8*length; printf("%d %d %.1lf\n",8*length,res,dd/res); } }int main(){ while(cin>>s&&s!="END"){ int i; for(i=0;i<60;i++){ alp[i].w=0; alp[i].key=i; } huf(); } return 0;}
- poj 1521
- poj-1521
- POJ 1521
- POJ 1521 Entropy
- poj 1521 Entropy
- POJ 1521 哈夫曼树
- poj 1521 Entropy
- POJ 1521 Entropy
- POJ 1521 Entropy
- POJ 1521 && HDOJ 1053
- POJ - 1521 Entropy
- Huffman编码 POJ 1521
- POJ 1521 Jungle Roads
- poj 1521 Entropy
- POJ 1521 , Entropy , Huffman
- POJ
- poj
- POJ
- windows下 python 关于管通道(程序回显)处理的一个小例子
- JS读取客户端文件研究
- Windows Phone开发(六)-- 多任务之墓碑机制
- SNMP之PDU
- H264码流打包分析
- poj 1521
- I/O体系结构和设备驱动程序(五)
- I/O体系结构和设备驱动程序(六)
- poj 1125 Stockbroker Grapevine
- 方正县连夜将日本开拓团石碑拆除
- HDU3917 Road constructions 最大权闭合图 2011 Multi-University Training Contest 8 - Host by HUST
- Handling Events in Windows
- 匹配练习
- 软件测试(白盒)