hdu 1053 Entropy

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1053  

Entropy

Description

An entropy encoder is a data encoding method that achieves lossless data compression by encoding a message with “wasted” or “extra” information removed. In other words, entropy encoding removes information that was not necessary in the first place to accurately encode the message. A high degree of entropy implies a message with a great deal of wasted information; english text encoded in ASCII is an example of a message type that has very high entropy. Already compressed messages, such as JPEG graphics or ZIP archives, have very little entropy and do not benefit from further attempts at entropy encoding.

English text encoded in ASCII has a high degree of entropy because all characters are encoded using the same number of bits, eight. It is a known fact that the letters E, L, N, R, S and T occur at a considerably higher frequency than do most other letters in english text. If a way could be found to encode just these letters with four bits, then the new encoding would be smaller, would contain all the original information, and would have less entropy. ASCII uses a fixed number of bits for a reason, however: it’s easy, since one is always dealing with a fixed number of bits to represent each possible glyph or character. How would an encoding scheme that used four bits for the above letters be able to distinguish between the four-bit codes and eight-bit codes? This seemingly difficult problem is solved using what is known as a “prefix-free variable-length” encoding.

In such an encoding, any number of bits can be used to represent any glyph, and glyphs not present in the message are simply not encoded. However, in order to be able to recover the information, no bit pattern that encodes a glyph is allowed to be the prefix of any other encoding bit pattern. This allows the encoded bitstream to be read bit by bit, and whenever a set of bits is encountered that represents a glyph, that glyph can be decoded. If the prefix-free constraint was not enforced, then such a decoding would be impossible.

Consider the text “AAAAABCD”. Using ASCII, encoding this would require 64 bits. If, instead, we encode “A” with the bit pattern “00”, “B” with “01”, “C” with “10”, and “D” with “11” then we can encode this text in only 16 bits; the resulting bit pattern would be “0000000000011011”. This is still a fixed-length encoding, however; we’re using two bits per glyph instead of eight. Since the glyph “A” occurs with greater frequency, could we do better by encoding it with fewer bits? In fact we can, but in order to maintain a prefix-free encoding, some of the other bit patterns will become longer than two bits. An optimal encoding is to encode “A” with “0”, “B” with “10”, “C” with “110”, and “D” with “111”. (This is clearly not the only optimal encoding, as it is obvious that the encodings for B, C and D could be interchanged freely for any given encoding without increasing the size of the final encoded message.) Using this encoding, the message encodes in only 13 bits to “0000010110111”, a compression ratio of 4.9 to 1 (that is, each bit in the final encoded message represents as much information as did 4.9 bits in the original encoding). Read through this bit pattern from left to right and you’ll see that the prefix-free encoding makes it simple to decode this into the original text even though the codes have varying bit lengths.

As a second example, consider the text “THE CAT IN THE HAT”. In this text, the letter “T” and the space character both occur with the highest frequency, so they will clearly have the shortest encoding bit patterns in an optimal encoding. The letters “C”, “I’ and “N” only occur once, however, so they will have the longest codes.

There are many possible sets of prefix-free variable-length bit patterns that would yield the optimal encoding, that is, that would allow the text to be encoded in the fewest number of bits. One such optimal encoding is to encode spaces with “00”, “A” with “100”, “C” with “1110”, “E” with “1111”, “H” with “110”, “I” with “1010”, “N” with “1011” and “T” with “01”. The optimal encoding therefore requires only 51 bits compared to the 144 that would be necessary to encode the message with 8-bit ASCII encoding, a compression ratio of 2.8 to 1.

Input

The input file will contain a list of text strings, one per line. The text strings will consist only of uppercase alphanumeric characters and underscores (which are used in place of spaces). The end of the input will be signalled by a line containing only the word “END” as the text string. This line should not be processed.

Output

For each text string in the input, output the length in bits of the 8-bit ASCII encoding, the length in bits of an optimal prefix-free variable-length encoding, and the compression ratio accurate to one decimal point.

Sample Input

AAAAABCD
THE_CAT_IN_THE_HAT
END

Sample Output

64 13 4.9
144 51 2.8

哈弗曼编码。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<queue>
#include<set>
using std::set;
using std::sort;
using std::swap;
using std::string;
using std::priority_queue;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 30;
const int INF = 0x3f3f3f3f;
typedef unsigned long long ull;
char buf[11000];
struct Node {
	char dat;
	int w;
	Node *ch[2];
	Node(char _dat_, int _w_, Node *l = NULL, Node *r = NULL) {
		dat = _dat_, w = _w_;
		ch[0] = l, ch[1] = r;
	}
	Node(const Node &x) {
		dat = x.dat, w = x.w;
		ch[0] = x.ch[0], ch[1] = x.ch[1];
	}
	inline bool operator<(const Node &x) const {
		return w > x.w;
	}
};
struct Hoffmancode {
	int sum;
	Node *root;
	priority_queue<Node> q;
	inline char to_lower(char ch) {
			return ch >= 'A' && ch <= 'Z' ? ch + 32 : ch;
	}
	inline void CreateHoffmanTree() {
		Node *l = NULL, *r = NULL;
		while (!q.empty() && q.size() != 1) {
			l = new Node(q.top()); q.pop();
			r = new Node(q.top()); q.pop();
			Node ret(0, l->w + r->w, l, r);
			q.push(ret);
		}
		if (!q.empty()) {
			root = new Node(q.top()); q.pop();
		}
	}
	inline void CreateHoffmanCode(Node *x, string str) {
		if (!x) return;
		if (x->dat != 0) {
			sum += (str.length() * x->w);
		}
		CreateHoffmanCode(x->ch[0], str + "0");
		CreateHoffmanCode(x->ch[1], str + "1");
	}
	inline void solve() {
		sum = 0, root = NULL;
		int arr[N] = { 0 }, tot = 0, n = strlen(buf);
		while (!q.empty()) q.pop();
		for (int i = 0; i < n; i++) {
			arr[to_lower(buf[i]) - '_']++;
		}
		for (int i = 0; i < 28; i++) {
			if (arr[i]) {
				tot++;
				Node ret('_' + i, arr[i]);
				q.push(ret);
			}
		}
		if (1 == tot) {
			printf("%d %d 8.0\n", n * 8, n);
			return;
		}
		CreateHoffmanTree();
		CreateHoffmanCode(root, "");
		printf("%d %d %.1lf\n", n * 8, sum, (double)(n * 8) / sum);
	}
}work;
int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w+", stdout);
#endif
	while (~scanf("%s", buf) && 0 != strcmp(buf, "END")) {
		work.solve();
	}
	return 0;
}

转载于:https://www.cnblogs.com/GadyPu/p/4865026.html

分布式系统中的“无状态”和“有状态”详解 有状态服务,即服务端需要记录每次会话的客户端信息,从而识别客户端身份,根据用户身份进行请求的处理,典型的设计如 tomcat 中的 session。例如登录:用户登录后,我们把登录者的信息保存在服务端 session 中,并且给用户一个 cookie 值,记录对应的 session。然后下次请求,用户携带 cookie 值来,我们就能识别到对应 session,从而找到用户的信息。 阅读详情

相关推荐

caxa二次开发实例展示

本人有8年CAXA各产品(如电子图版、工艺图表、PDM等)二次开发经验,参与过国家电网南瑞集团、中石油、龙记集团、欧姆龙集团、港日集团、中集集团、中国五矿、方圆塑机、大连锅炉、金蝶PDM集成CAXA,TEAMCENTER集成CAXA、大连锅炉机械、中国中车等项目的开发,擅长CAXA电子图版、CAXA工艺图表的二次开发,有需要的可以联系我,电话:13169467685、13249738576 Q

hourui800720的专栏 8045

哈夫曼编码压缩比问题:POJ1521 熵

题目描述: An entropy encoder is a data encoding method that achieves lossless data compression by encoding a message with "wasted" or "extra" information removed. In other words, entropy encoding removes information that was not necessary in the first place t

qq_48988844的博客 825

pycharm添加Anaconda解释器显示不出来

因为我之前下载的是pycharm最新版本2024.1的,所以我抱着试一试的心态卸载重装了2021.3.3的,创建新文件的时候立刻就自己识别好了conda环境。就是图中画圈的地方,之前一直显示为python的图标,但是再Python Interpreter后面跟的路径确实是我下载anaconda的地方。另外一种方法就是使用Virtualenv Environment方式配置,但是我的pycharm还是没有识别出conda的图标。首先是这位的方法,先添加系统解释器,再重启,但是我的图标还是python。

2202_75803271的博客 4019

POJ - 1521 Entropy(哈夫曼编码)

题目链接:https://vjudge.net/contest/361484#problem/J An entropy encoder is a data encoding method that achieves lossless data compression by encoding a message with “wasted” or “extra” information removed...

zaiyang遇见 623

Cursor 被封解决方案 - 8元轻松搞定永久账号

最近两天很多这种问题,比如:Access blocked,please contact your admin,本文亲测解决有效

欲穷java洞的博客 2万+

QQ音乐商业化客户端开发工程师:岗位深度解析与面试攻略

先看钱从哪里来。腾讯音乐 2026 年 Q3 财报显示,总收入 89.4 亿元,其中音乐相关服务收入 76.8 亿元;音乐会员服务收入 49.9 亿元营销及消费类服务收入 27.0 亿元,后者同比增长 12.1%,增速比会员还快(来源:TME 2026 Q3 财报公开报道)。它们全都要经过客户端这一层。用户点"开通连续包月",走的是客户端的支付链路;用户看到开屏广告、信息流广告、激励视频,走的是客户端的广告 SDK 与曝光监测;

郑伟强dev的专栏 378

霍夫曼树的应用

Entropy Time Limit:1000MS Memory Limit:65536K Total Submit:23 Accepted:13 Description An entropy encoder is a data encoding method that achieves lossless data compression by encoding a message wit

Wei_Yuan_2012的专栏 1256

YOLOv26全流程实战手册:从yaml配置拆解到训练推理参数调优(附虚拟环境搭建)

以“车辆、行人、小型物体”3类数据集为例,修改# 1. 修改类别数nc: 3# 2. 调整锚框(适配小目标)anchors:- [12,16, 16,24, 33,23] # 增加小锚框# 3. 轻量化调整(边缘部署)depth_multiple: 0.25 # 降低深度系数width_multiple: 0.20 # 降低宽度系数# 其余Backbone/Head结构不变yaml配置:核心是调整nc(类别数)、(轻量化)、anchors(适配目标尺度);虚拟环境。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 885

Entropy (p1521)

像这样的题的思路,我是很难想到的。只好看人家的,不好,不好。 #include #include #include #include #include #include #include #include #include #include #include using namespace std; priority_queue,greater> q; int len[1000];

jiangjiashi的博客 867

Python电商网站全站爬虫实战:以京东为例的数据采集与分析

随着电子商务的蓬勃发展,电商数据已成为市场研究、竞争分析和消费者行为研究的重要资源。本文详细介绍了如何使用Python最新技术栈构建一个高效的电商网站全站爬虫,以京东为例实现商品数据的自动化采集。文章涵盖了爬虫的法律与伦理考量、技术选型、反爬虫策略应对、分布式架构设计以及数据存储方案,并提供了完整的代码实现。本爬虫系统采用Scrapy-Redis分布式框架、Selenium动态渲染、智能代理轮换和机器学习验证码识别等先进技术,能够稳定高效地抓取京东全站商品数据,为电子商务研究提供数据支持。关键词。

2201_76125261的博客 421

基于SAGE算法的宽带信道参数估计算法的MATLAB仿真

本文将介绍如何使用MATLAB进行SAGE算法的仿真,以便更好地理解和应用该算法。SAGE算法是一种基于最大期望(Expectation-Maximization)方法的迭代估计算法,用于估计未知的参数。在宽带信道参数估计中,SAGE算法通过迭代优化来估计信道的传输函数。总结起来,本文介绍了如何使用MATLAB进行基于SAGE算法的宽带信道参数提取算法的仿真。通过以上步骤,我们可以得到估计的信道响应,并与真实信道响应进行比较。此外,SAGE算法还可以与其他信道估计算法相结合,以提高估计的准确性和性能。

CodeRoarX的博客 1087

贪心算法之Entropy

Entropy Description An entropy encoderis a data encoding method that achieves lossless data compression by encoding amessage with "wasted" or "extra" information removed. Inother words, entropy enco

hqf1992的专栏 722

基于FPGA的相控阵雷达波束控制系统设计(2)

也就是在计算波控码时0,按2.8125递增,取遍-90

qq_43416206的博客 1821

hdu 1053Entropy

hdu 1053Entropy 给定一个字符串,计算hu

gwq5210的专栏 853

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Hdu 1053 Entropy

大意:裸地哈弗曼编码,而且不要求输出编码,只要求输出最短长度。 思路:可以与Hdu 2527 用一样的方法水过,因为这里不需要求编码,但我写这一题主要是为了学习哈弗曼建树,所以也用建树的方法写了一遍。建好树后,我们可以通过DFS遍历树,也可以通过BFS遍历树。 CODE: #include #include #include #include using namespace st

Wall_F的专栏 909

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU1053 Entropy

Entropy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6285    Accepted Submission(s): 2647 Problem Description An entropy encoder

BorntoDo的博客 424

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

HDU 1053 Entropy

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1053 题目意思:给定一个字符串,这个字符串只由大写字母和下划线组成,在计算机中,每个字母占8个字节,如果不使用编码,所需的空间是多少字节?如果使用编码,那么所需的空间是多少字节。最后输出不使用编码所占的空间,使用编码所占的空间,以及它们的比值。 不使用编码的话,那么很显然,所占空间=字符串的长

哇哈哈的专栏 621

HDU1053——Entropy,HDU1054——Strategic Game,HDU1055——Color a Tree

如果我们改为用位模式“00”编码“A”,“01”编码“B”,“10”编码“C”,“11”编码“D”,那么我们可以仅用 16 位来编码此文本;一个最优编码是用“0”编码“A”,“10”编码“B”,“110”编码“C”,“111”编码“D”。一种这样的最优编码是用“00”编码空格,“100”编码“A”,“1110”编码“C”,“1111”编码“E”,“110”编码“H”,“1010”编码“I”,“1011”编码“N”和“01”编码“T”。然而,字母“C”、“I”和“N”只出现一次,所以它们将具有最长的代码。

u014114223的博客 1151

杭电hdu 1053 Entropy题解

http://acm.hdu.edu.cn/showproblem.php?pid=1053 这题就是运用哈夫曼的编码思想,然后统计用哈夫曼编码后的二进制长度,以及运用ascii编码长度的比较。我在这题上感觉统计无从下手,虽然知道哈夫曼的贪心实现,但真正的到运用的时候了,却一时想不起应该怎么用代码去实现,进过参考别人用优先队列写的代码,我也写出了我自己的代码。现记录在下面。做个在编程上的参考。

凌语小辉 2578
上一篇: hdu 5444 Elven Postman
下一篇: poj 2777 Count Color
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址