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 - ...
随机推荐
- java开发中中文编码问题
//ajax以get方式提交,字符串中包含中文 //后台struts中对该string的set方法中 this.jsonString = new String(jsoString.getBytes(& ...
- 1.1:Get Started with Unity Shaders
文章著作权归作者所有.转载请联系作者,并在文中注明出处,给出原文链接. 本系列原更新于作者的github博客,这里给出链接. 第1章开始正式进入Unity Shader的学习. 什么是Shader 本 ...
- D8 双连通分量
记得有个梗那一天,zw学生zzh大佬说逃不掉的路变成a不掉的题哈哈哈哈: 分离的路径: BZOJ 1718POJ 3177LUOGU 286: 思路:在同一个边双连通分量中,任意两点都有至少两条独立路 ...
- poj 3294 Life Forms - 后缀数组 - 二分答案
题目传送门 传送门I 传送门II 题目大意 给定$n$个串,询问所有出现在严格大于$\frac{n}{2}$个串的最长串.不存在输出'?' 用奇怪的字符把它们连接起来.然后求sa,hei,二分答案,按 ...
- 面向对象的封装(私有化)及@property(查看)/@setter(修改)!!!
面向对象有三大特性,继承,多态,封装继承可以减少代码重复量,多态可以用多继承模仿别的语言的建立规则约束子类封装为类的属性/方法的私有化,可以限制别人看,读,修改的权限,目前理解做记录,日后温习,回顾, ...
- Ansible在Ubuntu上的安装
#apt安装 apt-get install software-properties-common apt-add-repository ppa:ansible/ansible apt-get upd ...
- Bootstrap3基础 text-uppercase/lowercase/capitalize 字母大写、小写和首字母大写
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- 百度AI搜索引擎
一.爬虫协议 与其它爬虫不同,全站爬虫意图爬取网站所有页面,由于爬虫对网页的爬取速度比人工浏览快几百倍,对网站服务器来说压力山大,很容易造成网站崩溃. 为了避免双输的场面,大家约定,如果网站建设者不愿 ...
- ipan笔记
// 对于mysql来说, 如果字段没有设置其 default值, 则会自动 设置 default值为null.同理没有设置not null, 则会自动允许null =yes // create ta ...
- win10 处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”
更新Win10,原来的IIS站点访问不了,原因是因为IIS 没有.net 4.5,使用网上的aspnet_regiis.exe -i命令,一点都不靠谱,直接提示: C:\WINDOWS\system3 ...