poj1521
来源:互联网 发布:网络英语培训排名 编辑:程序博客网 时间:2024/06/05 03:40
#include <iostream>#include <queue>#include <string.h>#include <stdio.h>using namespace std;int main(){ string s; int ch[300]; priority_queue<int ,vector<int>,greater<int> >q; while(cin>>s && s!="END") { memset(ch,0,sizeof ch); int len=s.length(); int len1=len*8; int len2=0; for(int i=0;i<len;i++) ch[s[i]]++; for(int i=0;i<300;i++) { if(ch[i]==0) continue; q.push(ch[i]); } while(q.size()>1) { int a=q.top();q.pop(); int b=q.top();q.pop(); len2+=a+b; q.push(a+b); } q.pop(); if(!len2) len2=len; printf("%d %d %.1f\n",len1,len2,len1*1.0/len2); //这里不要写%.1lf……这个bug找了好久…… }}
注意每两项之和就是代码长度!
阅读全文
0 0
- poj1521
- poj1521
- POJ1521
- poj1521
- poj1521(huffman)
- poj1521 huffman
- poj1521 Entropy
- poj1521 (huffman +优先队列)
- [POJ1521]Huffman编码
- #POJ1521#Huffman编码
- [POJ1521]Huffman编码
- poj1521 求赫夫曼编码长度
- ZOJ1117 POJ1521 HDU1053 Huffman编码
- ZOJ1117 POJ1521 HDU1053 Entropy,哈夫曼编码问题
- poj1521 指数型母函数 整数分式
- HDU1053,POJ1521,ZOJ1117 Entropy 哈夫曼编码
- 【POJ1521】【HDU1053】Entropy 哈夫曼(Huffman)编码
- POJ1521---哈夫曼编码,求最优WPL
- 3666 小C语言--词法分析程序
- scrapy爬取豆瓣电影top250并存储到mysql
- 《电路计算C++与MATLAB》学习笔记(六)
- 触摸屏:屏幕键盘(虚拟键盘)解决方案
- C/C++中static关键字作用
- poj1521
- centos6安装elasticsearch6错误笔记
- ThinkPadT420装双系统
- 2147 表达式语法分析——递归子程序法
- CPP 调用Python
- yum提示Another app is currently holding the yum lock; waiting for it to exit...
- 抽象类和接口的部分小节
- Linux基础 30分钟GDB调试快速突破
- 推荐算法与伦理