huffman(greedy)
present a file by binary character code,let the less characters can be presented simplier.
package greedy; import java.util.Iterator;
import java.util.LinkedList; public class huffman {
private static class Node{
private Node left ;
private Node right ;
private int freq;
public Node(Node left,Node right,int freq){
this.left = left;this.right = right; this.freq = freq;
}
} public Node Huffman(LinkedList<Node> list){
int n = list.size();
for(int i = 1;i <= n-1;i++){
Node x = list.removeFirst();
Node y = list.removeFirst();
Node node = new Node(x,y,x.freq + y.freq);
for (int j = 0;j < list.size() - 1;j++){
if(node.freq >= list.get(j).freq && node.freq <= list.get(j+1).freq){
list.add(j+1,node);
}
else if( j+1 == list.size() - 1){
list.addLast(node);
} } }
return list.getFirst(); } }


huffman(greedy)的更多相关文章
- hdu 1053 (huffman coding, greedy algorithm, std::partition, std::priority_queue ) 分类: hdoj 2015-06-18 19:11 22人阅读 评论(0) 收藏
huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commente ...
- Greedy is Good
作者:supernova 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=greedyAlg Joh ...
- [Optimization] Greedy method
Given two sequences of letters A and B, find if B is a subsequence of A in thesense that one can del ...
- 贪婪算法(Greedy Algorithm)
Greedy Algorithm <数据结构与算法--C语言描述> 图论涉及的三个贪婪算法 Dijkstra 算法 Prim 算法 Kruskal 算法 Greedy 经典问题:coin ...
- 哈夫曼(huffman)树和哈夫曼编码
哈夫曼树 哈夫曼树也叫最优二叉树(哈夫曼树) 问题:什么是哈夫曼树? 例:将学生的百分制成绩转换为五分制成绩:≥90 分: A,80-89分: B,70-79分: C,60-69分: D,<60 ...
- USACO . Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- (转载)哈夫曼编码(Huffman)
转载自:click here 1.哈夫曼编码的起源: 哈夫曼编码是 1952 年由 David A. Huffman 提出的一种无损数据压缩的编码算法.哈夫曼编码先统计出每种字母在字符串里出现的频率, ...
- [老文章搬家] 关于 Huffman 编码
按:去年接手一个项目,涉及到一个一个叫做Mxpeg的非主流视频编码格式,编解码器是厂商以源代码形式提供的,但是可能代码写的不算健壮,以至于我们tcp直连设备很正常,但是经过一个UDP数据分发服务器之后 ...
- jpeg huffman coding table
亮度DC系数的取值范围及序号: 序号(size) 取值范围 0 0 1 - ...
随机推荐
- MySQL MHA 报错处理
安装环境:CentOS 6.5 MySQL 5.7.22 MHA 0.56 1.找不到mysql 命令 Sat Mar 23 07:17:50 2019 - [info] Connecting to ...
- Linux(5.5版为主)的基本操作命令
mount 查看挂载目录 cat ~ 查看文件下的内容 touch ~ 创建一个文件 一次性性创建几个文件: touch /tmp/{1,2,3,4}.txt ...
- Shell 常用技巧
Shell 常用技巧 echo $RANDOM | cksum | cut -c - openssl rand -base64 | cksum | cut -c - date +%N | cut -c ...
- 时间序列数据库调研之InfluxDB
基于 Go 语言开发,社区非常活跃,项目更新速度很快,日新月异,关注度高 测试版本 1.0.0_beta2-1 安装部署 wget https://dl.influxdata.com/influxdb ...
- SVN更新的时候前面的子母的意思(A C D M G U R I)
U:update 表示从服务器收到文件更新了 G:表示本地文件以及服务器文件都已更新,而且成功的合并了 其他的如下: A:add 表示有文件或者目录添加到工作目录 R:replace,从服务器替换,表 ...
- topcoder srm 590 div1 (max_flow_template)
problem1 link 对于每一个,找到其在目标串中的位置,判断能不能移动即可. problem2 link 如果最后的$limit$为$11=(1011)_{2}$,那么可以分别计算值为$(10 ...
- P3327 [SDOI2015]约数个数和
思路 做这题先要知道一个性质, \[ d_{ij}=\sum_{x|i}\sum_{y|j}[(x,y)=1] \] 然后上莫比乌斯反演颓柿子就好了 \[ \begin{align}&\sum ...
- JS函数、变量作用域
函数参数 函数的()中指定一个或多个形参(形式参数),多个形参之间用,号隔开,声明形参相当于在函数内部声明了对应的变量,但不赋值.在调用时在()中指定实参 调用时解析器不会检查实参类型.数量,实参可 ...
- LINQ之路13:LINQ Operators之连接(Joining)
Joining IEnumerable<TOuter>, IEnumerable<TInner>→IEnumerable<TResult> Operator 说明 ...
- vue的环境配置
在vue越来越火的情况下,本人也开始加入到大军当中. 首先,列举下我们需要的东西: node.js 环境(npm包管理器) vue-cli 脚手架构建工具 cnpm npm的淘宝镜像 安装node.j ...