bzoj4198 [Noi2015]荷马史诗(Huffman编码+stl)

Python爬虫实战:京东/淘宝商品价格与评论监控系统——从User-Agent伪装到编码陷阱的全面攻克 在电商数据驱动决策的今天,无论是个人消费者想抓住历史低价,还是市场分析师需要追踪竞品动态,抑或是算法交易员依赖实时价格信号,自动化的商品价格与评论监控系统都已成为不可或缺的工具。然而,电商平台的反爬虫策略日益严苛,字符编码的“暗坑”更是让初学者屡屡碰壁。本文将以京东(JD.com和淘宝(Taobao.com两大主流平台为目标,手把手带你构建一个稳定、高效的商品监控爬虫。User-Agent伪装——如何模拟真实浏览器行为,突破初级反爬。GBK/UTF-8编码混战。 阅读详情

题目给出的定义显然就是让我们求Huffman编码。
不过可能是K叉的,我们加几个0补全就好了。
为了满足第二个要求,贪心的权值相同时深度小的优先。

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
#define pi pair<ll,int>
inline char gc(){
    static char buf[1<<16],*S,*T;
    if(S==T){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}
    return *S++;
}
inline ll read(){
    ll x=0,f=1;char ch=gc();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=gc();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();
    return x*f;
}
int n,K;
ll ans=0;
priority_queue<pi,vector<pi>,greater<pi> >q;
int main(){
//  freopen("a.in","r",stdin);
    n=read();K=read();
    for(int i=1;i<=n;++i) q.push(make_pair(read(),0));
    if((n-1)%(K-1)){
        int tmp=(n-1)%(K-1)+1,dep=0;ll res=0;
        while(tmp--){
            res+=q.top().first,dep=max(dep,q.top().second+1);q.pop();
        }ans+=res;q.push(make_pair(res,dep));
    }int tmp=(n-1)/(K-1);
    while(tmp--){
        ll res=0;int dep=0;
        for(int i=1;i<=K;++i){
            res+=q.top().first,dep=max(dep,q.top().second+1);q.pop();
        }ans+=res;q.push(make_pair(res,dep));
    }printf("%lld\n%d\n",ans,q.top().second);
    return 0;
}
Allegro因为精度问题导致走线连接不上的解决办法 在用Allegro做PCB设计的时候,尤其是从其它单板上导数据过来的时候,有时会因为精度不一致导致连接不上,如下图。一般来说,可以逐个重新连接一下,但是如果连接点位比较多的话,需要花费较多时间。下面介绍如何使用Allegro自带的功能解决这个问题,具体操作如下。和Convert Figure Stackups to vias。因为精度问题导致走线连接不上的解决办法。线和过孔因为精度有微小的连接偏差。 阅读详情

相关推荐

别再乱改宏定义了!STM32F103程序移植保姆级教程(从C8T6到ZET6实战)

本文详细解析了STM32F103程序从C8T6移植到ZET6的实战步骤,重点介绍了硬件差异、开发环境配置、时钟陷阱及外设处理等关键点。通过修改宏定义(如STM32F10X_HD)、调整启动文件和时钟配置,确保移植顺利进行。适合嵌入式开发者参考,避免常见移植问题。

weixin_42567497的博客 221

【Huffman树】【贪心】【NOI 2015】【bzoj 4198】荷马史诗

4198: [Noi2015]荷马史诗Time Limit: 10 Sec Memory Limit: 512 MB Submit: 127 Solved: 80 Description追逐影子的人,自己就是影子。 ——荷马 Allison 最近迷上了文学。她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的《荷马史诗》。但是由《奥德赛》和《伊利亚特》组成的鸿篇巨制《荷马史诗》

morestep的专栏 2641

MATLAB下pdf文件操作读取示例

当遇到一些需要大量数据的项目,数据的读取与储存显得尤为重要。怎样把数据从其他格式的文件中读取,并运用到程序中是很多时候我们要解决的问题。对于平常的.txt,和.xlsx文件,MATLAB有对应的函数帮助读取,但是遇到pdf文件时MATLAB很难读取内容。本文以一个操作实例提供了一个从pdf文件中读取数据的方法。

UESTC 五高考3模拟的博客 6563

bzoj4198 [Noi2015] [荷马史诗] Huffman 编码

HUFFMAN编码

Venishel的博客 448

Linux内存优化:KSM技术原理与实践指南

内存共享是提升虚拟化环境资源利用率的关键技术,其核心原理是通过识别相同内容的内存页进行合并。Linux内核的KSM(Kernel Samepage Merging)机制采用红黑树数据结构管理内存页,通过多级哈希比较算法实现高效合并。该技术能显著降低物理内存消耗,提升CPU缓存命中率,特别适用于运行大量相似虚拟机实例的场景。在容器化和云计算环境中,KSM与NUMA优化、内存气球等技术协同,可实现40%-60%的内存节省。典型应用包括金融云平台的高密度虚拟机部署,以及Kubernetes集群的基础镜像优化。

weixin_28730353的博客 373

python模拟银行交易流水

模拟自动生成银行交易流水,其中包括:入账账号、出账账号、交易金额、交易余额、交易时间、出入表示关键字段

qq_31823889的博客 2918

[NOI2015]荷马史诗

嘟嘟嘟 在luogu上看到这是一道蓝题,结果自己想了一个多点也没做出来…… 但是自己概括的题意还是很准的:构建一棵最多有\(K\)个叉的\(n\)个叶子节点的树,每一个叶子节点有一个给定的权值,使每一个叶子节点的权值*到根节点的距离之和最小。 当时只发现了如果把权值从大到小排序,那么他们距树根的距离一定是单调不减的。然后按这个方法爆搜+\(w_i\)都相等的情况,总共就拿了40分。...

weixin_30455661的博客 188

YOLOv10涨点改进:SPPF原创自研创新 | SPPF创新结构,重新设计全局平均池化层和全局最大池化层,增强全局视角信息和不同尺度大小的特征

SPPF原创自研创新

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 2091

k叉哈夫曼树(bzoj-4198荷马史诗)

k叉哈夫曼树在ACM中的最常用的应用就是求合并n个数最小的代价。 哈夫曼树也可以是k叉的,只是在构造k叉哈夫曼树时需要先进行一些调整。构造哈夫曼树的思想是每次选k个权重最小的元素来合成一个新的元素,该元素权重为k个元素权重之和。但是当k大于2时,按照这个步骤做下去可能到最后剩下的元素少于k个。 解决这个问题的办法是假设已经有了一棵哈夫曼树(且为一棵满k叉树),则可以计算出其叶节点数目为(k-1...

wangtao的博客 645

Kriging克里金模型实现数据回归预测Matlab代码

Kriging克里金模型实现数据回归预测Matlab代码

天天酷科研的博客 614

【WRF工具】WRF Domain Wizard第一期:软件下载及安装

【WRF工具介绍】WRF Domain Wizard-确定模拟区域

WW、forever的博客 2923

【NOI2015】荷马史诗

  题目链接 https://www.luogu.org/problem/P2168   题目大意是给定n 个单词的出现次数wi,求用k进制的前缀码转换后得到的最小总长度,以及在保证总长度最小时的最长串 si 的长度最短。   这题现在来看算是NOI里很简单的了(我竟然凹出来了w),但是据说当时这题可是难倒一大片。首先是因为这题题干太长不怎么容易看懂,另外可能是因为当时哈弗曼树还...

a1137775617的博客 708

2.STM32F407ZGT6 学习笔记-移植 FreeRTOS

1. 在工程下建议FreeRTOS文件夹 2. 在FreeRTOS文件夹下建立 src 和 port 文件夹 (src用于存放freertos源码,port文件夹存放内存和接口相关的文件) 3. 复制freertos/source文件夹下所有c文件复制到刚刚建立的freertos/src目录下 4. 复制FreeRTOSv9.0.0\FreeRTOS\Source\portablex下的MemMang和RVDS文件夹复制到刚刚建立的port问价夹下 5. 将FreeRTOSv9.0.0\FreeRTOS

Car12 1236

【NOI2015】bzoj4198 荷马史诗

贪心+堆

YHaX的博客 921

IEM模型,地表粗糙度模拟

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

深度学习工具包 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")

BZOJ4198 荷马史诗 堆

题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=4198 分析 Huffman编码,每次取出权值最小的 kkk 个点进行合并。 为了保证之后取时不会不足 kkk 个点而使答案不最优,要加入一些权值为 000 的点“占位”。 题目要求最长的字符串尽量短,每个节点除了权值再维护下合并次数即可,取时权值一样则取合并次数少的。 AC代码 #inc...

Kevin的博客 444

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

NOI 2015 荷马史诗 k叉哈夫曼树 堆优化

NOI 2015 荷马史诗 K叉哈夫曼树 堆优化 AC解法

Quack 3059

NOI 2015 荷马史诗 (哈夫曼树)

【NOI2015 Day2】荷马史诗问题描述 追逐影子的人,自己就是影子。 ——荷马 Allison 最近迷上了文学。她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的《荷马史诗》。但是由《奥德赛》和《伊利亚特》组成的鸿篇巨制《荷马史诗》实在是太长了,Allison 想通过一种编码方式使得它变得短一些。 一部《荷马史诗》中有 n 种不同的单词,从 1

Mogician_Evian的博客 747

bzoj4198 [Noi2015]荷马史诗

题意:k叉哈夫曼树 题解:2叉哈夫曼树的做法我们知道后,k叉哈夫曼树就是每次找前k小的。但是现在的问题是可能有非满叉结点。考虑到非满叉结点一定是在最后一层,所以只需要补x个0即可。推一推知道是x = k - 1 - (n - 1) % (k - 1)。#include<bits/stdc++.h> #define ll long long using namespace std; struct N

yxr0105 398

【bzoj4198】[Noi2015]荷马史诗 哈夫曼树

Description 追逐影子的人,自己就是影子。 ——荷马 Allison 最近迷上了文学。她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的《荷马史诗》。但是由《奥德赛》和《伊利亚特》组成的鸿篇巨制《荷马史诗》实在是太长了,Allison 想通过一种编码方式使得它变得短一些。 一部《荷马史诗》中有 n 种不同的单词,从 1 到 n 进行编号。其中第 i 种单词出现的

wang_sj的博客 420

【BZOJ4198】【UOJ130】【NOI2015】荷马史诗

【题目链接】BZOJUOJ【思路要点】如果将一个合法的分配方案放到字典树上,那么每一个关键节点均为叶子结点。考虑如何使答案最小化,数据范围较大,考虑贪心。我们注意到一系列具有相同父亲的叶子结点可以被看作一个大小为它们大小总和的叶子结点。我们称之为一次合并,我们不断地执行合并,最后就会得到字典树上的根节点。由于我们希望使最小化答案,而一个叶子结点被合并的次数越多,其大小在答案中被计算的次数也越多,所...

cz_xuyixuan的博客 349

bzoj4198 [Noi2015]荷马史诗 k叉哈夫曼树

k叉哈夫曼树 二叉就是贪心,找最小的两个合并,想当年记得是用。。两个数组存的吧。。只是tooyoungtoosimple。。虽然是O(n),优先级队列O(nlogn)。。 k叉的是添加x个w值为0节点,使得最后组成的是每个节点要么是叶子,要么是有k个儿子,数学(?)推导一下即可。#include<iostream> #include<cstdio> #include<algorithm> #in

yxr0105 942

【BZOJ4198】荷马史诗,贪心之k叉哈夫曼树

.

xiaoyimi的博客 630

BZOJ4198或UOJ130 荷马史诗 【K叉哈夫曼树】【堆】

题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4198 http://uoj.ac/problem/130题解: 用一个堆来维护一个K叉哈夫曼树,如果无法合并(即n-1不为k-1的倍数时),就补充n-k个虚拟节点,节点的权值为0(不会影响结果),再合并即可。代码:#include <cstdio> #include <cst

BlueSky 642

NOI 2015 荷马史诗

题意: 扩展的Huffman编码(由以前的二进制变为了k进制) 求编码后文章最短长度和Huffman树的最小高度(或者说最长串最短长度,当然是在文章最短前提下) 你不知道Huffman编码? 你知道Huffman编码但不知道是怎么回事? 看CLRS(算法导论)贪心那一章吧,无比详细,伪代码,图解,证明样样俱全; 你没有CLRS? 白书(算法竞赛入门经典)上也有(但不如CLRS的详细);

zzyu5ds的专栏 921

【bzoj4198】[NOI2015]荷马史诗

k-哈夫曼树

zhaoyh2000的博客 511

bzoj4198

一道简单的k叉霍夫曼树,注意要用无符号长整形啊啊!!64位整数!!!不然会re的!!#include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;algorithm&gt; #include&lt;queue&gt; using namespace std; typedef unsigned long long ll; struct nod...

guoshiyuan484的博客 270

bzoj4198 noi2015 荷马史诗

k叉哈夫曼树,平衡整颗树即可 然后开个双队列由小到大做 #include #include #include #include #include #include #define LL long long #define fo(i,a,b) for(int i=a;i<=b;i++) #define efo(i,x) for(int i=last[x];i!=0;i=e[i].next) us

BPM136 700
上一篇: bzoj4199 [Noi2015]品酒大会(SAM+线段树)
下一篇: CF392E Deleting Substrings(区间dp)
Icefox_zhx
博客等级 码龄10年 81粉丝 1239原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值