1521 Entropy

CPU 访问外设的两种核心机制:MMIO(Memory-Mapped I/O) 和 DMA(Direct Memory Access) BAR和DMA是计算机系统中两种关键的数据传输机制:BAR(基址寄存器)用于CPU与设备间的控制通信,映射设备寄存器便于配置操作;而DMA(直接内存访问)允许设备直接读写系统内存,无需CPU参与大量数据传输。典型场景如NVMe SSD读取数据时,CPU通过BAR下发指令,设备通过DMA高效传输数据到主机内存,最后中断通知CPU。虽然BAR能映射大内存空间,但仍无法替代DMA的高效数据传输功能,两者各司其职——BAR负责控制,DMA专注数据传输,共同实现高性能的硬件交互。 阅读详情

 

Entropy
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 1589 Accepted: 652

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

Source

 

 

【C++PCL】点云文件读写 本文介绍 PCL 中 PCD 与 PLY 点云文件的读取、保存和字段检查,覆盖 PointXYZI、PointXYZRGB、ASCII、二进制及压缩二进制,并给出 C++11 实操代码与参数调试建议。 阅读详情

相关推荐

从命名玄学看单片机江湖:STC、STM32与ESP32的型号密码与设计哲学

本文解析了STC、STM32和ESP32三大主流单片机系列的型号命名规则,揭示了其背后的设计哲学与市场策略。通过详细解读STC89C52、STM32F103C8T6等具体型号,帮助开发者理解芯片核心特性、性能等级及适用场景,为嵌入式系统选型提供实用指南。

g5h6i的博客 762

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遇见 615

机器学习——Anaconda下载安装教程

Anaconda详细下载安装教程

2401_83693485的博客 3067

[解题报告]POJ_1521.Entropy 哈夫曼树

题目非常长,大致看了下,赤裸裸的HUFFMAN树,是数据结构中很基础的东西了,以前写过求HUFFMAN编码的程序,但是感觉这题没有必要把HUFFMAN全部球出来,上网查了一下,找到了一种不错的解法,是使用优先队列来解的. 关于Huffman树有什么不了解的可以看这篇文章,讲解的很详细,http://blog.youkuaiyun.com/hairetz/archive/2009/05/05/415186

飞熊入梦 1108

CORS(跨域资源共享)漏洞解决方法

最近,测试环境上的项目被360测试人员检测出来有一个CORS漏洞,以下记录下漏洞问题与解决方法。 一、低危漏洞:CORS漏洞问题 测试人员访问某个url,将请求头中的Origin字段修改为任意值,结果仍然能获得正确的响应报文,就说明有CORS漏洞。 当CORS的设置不正确时,就会带来安全问题;当响应头中的Access-Control-Allow-Origin设置为null或*时,表示信任任何域,这时候就可能引入安全问题。 修复方法是合理配置CORS,判断Origin是否合法;具体说就是不让在nginx或t

BHSZZY的博客 3万+

[QMT量化交易小白入门]-二十四、年化收益47%的全球核心资产轮动策略(含代码解析)

m_days = 25 #动量参考天数period=200m_days被设置为25,表示动量参考的天数为25天;period被设置为200,用于指定获取市场数据的周期长度。

木头大左的博客 2969

poj1521

哈夫曼树的应用

zjsru_Beginner的博客 971

【Kubernetes】Kubernetes 安全沙箱深度对比:gVisor vs Kata Containers

Kubernetes安全沙箱深度对比:gVisor和Kata Containers在架构、性能与安全性方面各有特点。gVisor通过用户态内核(Sentry)实现软件隔离,启动快(毫秒级)但CPU开销大(20-30%),适合Web服务等场景。Kata Containers采用轻量级虚拟机提供硬件级隔离,启动较慢(1-2秒)但兼容性更好,适合金融等高安全需求。测试显示gVisor在动态请求下性能下降33%,而Kata性能接近原生。建议根据场景选择:多租户/快速启动用gVisor,敏感数据/极致安全用Kata,

九师兄 178

贪心1003 POJ 1521-Entropy

典型HUFFMAN树的问题,用了STL的priority_queue#include #include #include using namespace std; class node{ public: int key; //a,b,c... int count;//频率 int p;//父亲结点 friend

shenggeliang的博客 316

论文阅读:ICLR 2026 Breaking and Fixing Defenses Against Control-Flow Hijacking in Multi-Agent Systems

该论文首先系统阐述了控制流劫持攻击的核心机理。此类攻击通过操纵多智能体系统的编排机制,诱导系统执行非安全操作,进而实现敏感信息窃取。攻击者将恶意指令伪装成环境错误信息,借助可信代理传递至系统编排器,利用"困惑副手"漏洞绕过传统安全防线。该论文指出,现有防御方案如LlamaFirewall所依赖的对齐检查机制存在根本性局限——安全目标与功能需求之间存在不可调和的内在冲突。该论文的核心贡献体现在攻防两个维度。

CSPhD-winston的博客 494

3D iToF深度分辨率测量

本文展示了RGB-D传感器在三维测量中的高精度表现。标靶深度图显示其具备清晰、低噪、无干扰的特性,点云数据完整度高且轮廓分明。该技术已成功应用于物流(体积测量误差<1%)、工业(高反光部件装配检测)和农业(果蔬成熟度分级)等领域,验证了其硬件和算法的可靠性,能够满足不同场景下的三维测量需求。

dream it possible 252

POJ1521---Entropy

POJ—Entropy 题目描述 英文 熵编码器是一种数据编码方法,其通过对去除了“浪费”或“额外”信息的消息进行编码来实现无损数据压缩。 考虑文本“AAAAABCD”。使用ASCII,编码需要64位。由于字形“A”以更高的频率出现,可以通过用更少的位编码来做得更好吗?最佳编码是将“A”编码为“0”,将“B”编码为“10”,将“C”编码为“110”,和“D”与“111”。(这显然不是唯一的最佳编码,因为很明显,对于任何给定的编码,B,C和D的编码可以自由地互换,而不会增加最终编码消息的大小。)使用此编码

LXYDSF的博客 941

ThingsBoard教程(一):ThingBoard介绍及安装

ThingsBoard介绍 最近看了很多开源的物联网的项目,其中有一个让我印象很深,那就是Thingsboard 下面我就给大家介绍一下这个项目,并指导大家如何在本地安装一个Thingsboard来体验它。 首先引用官网的项目介绍就是 一个开源的用于数据收集,处理,可视化和设备管理的开源物联网平台。 它通过行业标准的物联网协议(MQTT,CoAP和HTTP)实现设备连接,并支持云和本地部署。ThingsBoard结合了可伸缩性,容错性和性能,因此您永远不会丢失数据。 用它开源收集链接设备,收集设备的数据,

知无涯 2万+

POJ 1521-Entropy 贪心问题

<br />题目来源:http://acm.pku.edu.cn/JudgeOnline/problem?id=1521<br /> <br />解题报告:<br /> <br />典型HUFFMAN树的问题,用了STL的priority_queue,调了一下午,郁闷<br /> <br />#include <iostream> #include <string> #include <queue> using namespace std; class node{ public: in

kindlucy的专栏 2543

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

poj 1521 Entropy

//哈夫曼树应用      //一种特殊情况  全为一种字符时,特殊处理 点击打开链接 #include #include int N=27; typedef struct {         char c;   int w;   int f,l,r; }HNode,*Htree; typedef struct {   char c;   int codenum;

GarySE 776

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

POJ 1521 Entropy

Huffman树: 题目链接:POJ1521#include #include #include using namespace std; int t[100],len; char c[1000]; int huffman() { int a,b,c,sum=0; priority_queue,greater >q;//priority_queue,greater > q;

WeberXie 1341

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ 1521 , Entropy , Huffman

http://poj.org/problem?id=1521 Entropy Time Limit: 1000MS Memory Limit: 10000K P.S. 原题真长 题目大意: 给定一些只包含 大写字母 和 下划线 的字符串,求利用huffman编码的原理,存储每个字符串需要的最少bit数。 Input The input fi

Stitch_11752的博客 716

poj1521 Entropy

//霍夫曼编码问题 #include #include #include #include using namespace std; int al[27],i,cnt; string s; int main(void){  while(cin>>s){   if(s=="END")break;   cnt=0;   for(i=0;i    al[i]=0;   for

StrangeSmell的专栏 471

poj 1521 Entropy

链接:http://poj.org/problem?id=1521 Description An entropy encoder is a data encoding method that achieves lossless data compression by encoding a message with "wasted" or "extra" information remove

坤哥的专栏 1021

Entropy POJ - 1521

哈夫曼编码题目 题目很长,具体题意是对于字符串进行编码,一种是用ascll编码,另一种是用哈夫曼编码,求两种编码的长度,和比值。 ascll编码的长度就是字符串的长度乘以8 哈夫曼编码 根据哈夫曼树可以解决报文编码问题。假设需要一个字符串“aaaabbbbccccdddeeeeffffaaaabbbbcceffffabbbbfffffff”进行编码,将它转换为唯一的二进制码,但要求转换出来的二进制...

weixin_46250672的博客 270

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

【POJ No. 1521】信息熵 Entropy

【POJ No. 1521】信息熵 Entropy

代码改变世界 385

POJ 1521 Entropy(哈夫曼Huffman编码)

题目来源:http://poj.org/problem?id=1521 Entropy Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9899   Accepted: 3637 Description An entropy...

da_kao_la的博客 495
上一篇: POJ 1505 Copying Books
下一篇: POJ 1523 SPF
bobten2008
博客等级 码龄18年 153粉丝 157原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值