HDU 2795 Billboard(线段树)

图形学常见概念小结 前言:本文记录《unity shader入门精要》和openGL相关学习过程中一些学习要点; 文章目录PBR流程渲染管线细分着色器的底层实现,应用原理常见的色调映射算法openGl和Direct X的区别PBR流程和URP渲染管线Camera loop(剔除)MVP矩阵变换光线追踪前向渲染和延迟渲染shader和材质的区别bloom原理后处理的理解高斯模糊实现原理图像处理中的边缘检测算子 PBR流程 小结:一套基于自然界微平面理论、能量守恒、菲涅尔反射、线性空间等的科学理论所实现的基于物理的渲染系统,包含一 阅读详情

题目链接:HDU 2795 Billboard

【题意】给你一张h*w(1 <= h,w <= 10^9)大小的海报,上面会张贴一些数量为n(1<=n<=200000)高度为1宽度不定的小纸条,然后输入一些小纸条的宽度,求出它所张贴的高度。小纸条张贴是尽量靠左靠上,如果不能张贴,就输出-1.

【思路】海报的数据特别大,思路就是用线段树来优化,但是高度h高达10^9,直接建树肯定会爆,但纸条最多有n(200000)张,于是可以用len = min(h, n)来进行建线段树[1, len],节点维护的是海报每一行的可利用空白宽度。每次查询优先往左子树查询,查询之后还要更新数据,保留新的可利用空白宽度。

【吐槽】第一次自己来写线段树,以前对线段树一直是一种仰望的心态,的确是很牛逼的算法,有二分的思想在里面,转换为logn的强大力量。但是真的不好写啊哭数据结构就是伤不起。

下面贴AC代码:

/*
** HDU 2795 Billboard
** Created by Rayn @@ 2014/05/08
** 线段树
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = 200005;

int tree[MAX<<2];

void BuildTree(int k, int l, int r, int val)
{
    tree[k] = val;
    if(l == r)
        return ;
    int mid = (l + r) / 2;
    BuildTree(k<<1, l, mid, val);
    BuildTree(k<<1|1, mid+1, r, val);
}
int Query(int k, int l, int r, int val)
{
    if(l == r && tree[k] >= val)
    {
        tree[k] -= val;
        return l;
    }
    int mid = (l + r) / 2, ans;
    if(tree[k<<1] >= val)
        ans = Query(k<<1, l, mid, val);
    else if(tree[k<<1|1] >= val)
        ans = Query(k<<1|1, mid+1, r, val);
    else
        ans = -1;
    tree[k] = max(tree[k<<1], tree[k<<1|1]);
    return ans;
}
int main()
{
    int h, w, n;
    while(scanf("%d%d%d", &h, &w, &n) != EOF)
    {
        h = min(h, n);
        BuildTree(1, 1, h, w);
        for(int i=0; i<n; ++i)
        {
            int wid;
            scanf("%d", &wid);
            printf("%d\n", Query(1, 1, h, wid));
        }
    }
    return 0;
}


极智AI | 谈谈为什么卷积加速更喜欢 NHWC Layout 本文主要讨论一下为什么卷积加速更加喜欢 NHWC 的数据排布。 阅读详情

相关推荐

(详细教程)opencv+pycharm+笔记本摄像头 做一个人脸识别

文章目录 前言 一、pandas是什么? 二、使用步骤 1.引入库 2.读入数据 总结 一、安装opencv-python 这里推荐使用pycharm直接安装opencv-python 打开文件——设置——python解释器——点击+号 搜索opencv-python,点击安装包,等待片刻即可安装好 检查是否安装好,新建一个项目输入以下代码,若无报错则安装好 import cv2 二、准备分类器 咱们使用opencv官方提供的分类器,包括面部识别,侧...

qq_52852432的博客 1万+

[HDU 2795]Billboard[线段树]

题目链接:[HDU 2795]Billboard[线段树] 题意分析: 有一个高度为h,宽度为w的广告板,给出n个海报,每个海报高度1,宽度x。问能否贴到广告板上,能输出贴到的行,否则输出-1。每张海报必须贴到能贴部分的最左上角。 解题思路: 用线段树区间存:区间中还能贴的最大宽度;每次查询整个区间,满足就继续,否则返回,当l == r时说明查询到了最满足的行,然后进行更新。 个人感受:

闲停 457

【计算机科学导论实验】加法图灵机模拟 题解

本文提供计算机科学导论课程“图灵机加法器”实验的个人思路,仅供参考。

Chavapa's blog 2578

HDU2795—Billboard 线段树

HDU2795—Billboard 在学校的入口处有一个巨大的矩形广告牌,高为h,宽为w。所有种类的广告都可以贴,比如ACM的广告啊,还有餐厅新出了哪些好吃的,等等。。   在9月1号这天,广告牌是空的,之后广告会被一条一条的依次贴上去。   每张广告都是高度为1宽度为wi的细长的矩形纸条。   贴广告的人总是会优先选择最上面的位置来帖,而且在所有最上面的可能位置中,他会选择最左面的位置,而且不能...

GYH0730的博客 399

Netron显示自定义属性,按属性设置不同节点的颜色

本文介绍了一种让Netron显示自定义颜色的方法,可根据某些属性,调整节点的颜色 需求背景: 在分析AI模型精度误差时,用不同等级的红色,表示误差的大小.可以直观地看到误差的传递关系

Hi20240217的博客 1513

【QT开发教程】Qt中的跨平台文件系统操作

文件系统操作是应用程序开发中经常需要处理的任务。Qt提供了一套跨平台的文件系统操作API,使开发者能够在不同操作系统上无缝地进行文件和目录操作。本文将介绍Qt中的跨平台文件系统操作,包括基本概念、常用类和方法以及实际示例。

科技改变人类,技术成就未来 981

hdu 2795 Billboard ( 线段树 )

http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7320 Accepted Submission(s)...

diansitao5461的博客 161

AI故障预测系统架构设计:5个核心模块+3种主流架构,收藏这篇就够了

深夜11点,某汽车工厂的生产线突然停机——核心机器人的轴承磨损过度导致卡壳。维修人员连夜抢修,直接损失超过50万元,还延误了客户的交货期。传统的“事后维修”或“定期维护”要么代价高昂,要么防不胜防。AI故障预测系统的出现,让“精准维护”成为可能——它能通过传感器数据提前7-30天预警故障,将停机损失降低80%以上。知道要做故障预测,却不知道怎么搭系统——数据怎么采集?特征怎么提取?模型怎么部署?架构怎么选?本文将解决这些问题:我们会拆解AI故障预测系统的5个核心模块,分析3种主流架构。

AIGC应用创新大全的博客 1020

HDU 2795 Billboard (线段树+贪心)

HDU 2795 Billboard (线段树+贪心) 手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.youkuaiyun.com/suncongbo/article/details/77488127 URL: http://acm.hdu.edu.cn/showproblem.php?pid=2795题目大意:有一个h*w的木板...

suncongbo's blog 179

PyQt5简介和安装

在initUI方法中,设置了窗口的标题和大小,并创建了一个按钮。PyQt5是一个功能强大的Python界面开发框架,可以轻松创建跨平台的图形用户界面应用程序。本文介绍了PyQt5的简介和安装方法,并提供了一个简单的示例应用程序来演示PyQt5的基本用法。PyQt5是一个功能强大的Python界面开发框架,它提供了丰富的工具和组件,用于创建跨平台的图形用户界面(GUI)应用程序。信号是控件发出的事件,槽是与之关联的处理函数。接下来,我们将编写一个简单的PyQt5应用程序,以演示PyQt5的基本用法。

XdKwargs的博客 223

数字逻辑Fundamentals of Digital Logic with Verilog Design | 3rd Edition Solutins Chapter 2(step by step)

数字逻辑第二章习题和详细步骤 2-1 ~ 2-78

weixin_62651190的博客 2308

hdu 2795 Billboard 题解 (线段树)

原题链接: hdu 题意简述 有一个h∗wh*wh∗w的板子,和nnn条广告。每条广告的高度都是111,给定宽度。nnn条广告会被依次放到这个板子上,对于每条广告,会找到最上面的一行去放。在这最上面的一行里,又会找最左边的位置放。给定nnn个宽度,请输出nnn行,表示每个广告会被放在第几行。如果这个广告没有合适的位置放置,输出−1-1−1。 输入 多组数据。对于每组: h w n //如上所示 w...

LightningUZ的博客 351

极智芯 | 解读国产CPU之海光

大家好,我是极智视界,本文分享一下 解读国产CPU之海光。希望我的分享能对你的学习有一点帮助。

极智视界 3319

HDU-Billboard-2795(线段树)

hdu2795 Billboard Time Limit: 20000/8000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14101Accepted Submission(s): 6046 Problem Description At...

110

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

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

【解题报告】 HDU 2795 Billboard -- 线段树的应用

题目大意:有一个广告板,告诉我们尺寸(即高度宽度),我们要贴广告,广告的尺寸规定为1*w,我们每次从最左上面开始贴,当给出的广告不够贴时,移到下一行贴。输出当前广告贴在第几行。 题目连接:->  HDU 2795 思路大意:拿高度来当"线段"进行拆分,每次更新一下贴完之后所剩余的长度,并顺便输出所在行即可。 接下来计算一下充当 线段树的数组 的宽度: 这个题目中广告版的高度范围比较大,1

生命有一种绝对 1186

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

HDU 2795 Billboard // 线段树 单点更新

题目描述HDU 2795 Billboard解题思路题目大意: 有一张h×w的矩形告示栏, 和 n 张 1×wi 的海报 海报每次张贴的位置为告示栏剩余位置的左上角. 要求支持下列操作: 1) 对于每张海报 输出其在告示栏的第几行 (若放不下, 则输出 -1)首先我们知道的是 告示栏上的海报最多只有n张, 即告示栏的行数最多只有n行有效 所以当输入的h大于n时, 令h = n 即可.

FZU_zyt的专栏_(:з」∠)_ 380

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

hdu 2795 Billboard 线段树 点更新

// hdu 2795 Billboard 线段树 点更新 // // 首先n最多是200000种,也就是说最多200000行, // 我们的线段树的区间保存的是L到R中最大的叶子节点的值 // 初始情况下都是板子的宽度。这样,每次放一块广告的时候 // 看1到h中最左边的叶子区间是什么就ok了,还是很好理解的 // // 做题的感悟,这道题其实是去年暑假集训的时候做的,当时 // 并不会,只会敲

TIMELIMITE的专栏 895

hdu 2795 Billboard -- 线段树

hdu 2795 Billboard 以h建立线段树维护最大值每个节点初始化最大值为w 对于每次改,从最左端开始找满足要求的位置 //#include<bits/stdc++.h> #include<iostream> #include<vector> //#include <unordered_map> using namespace std; //template<class...Args> //void debug(Args... args)

weach的博客 219

HDU 2795 Billboard(线段树)

题目链接:HDU 2795 Billboard 线段树单点更新,

fobdddf的专栏 562

HDU 2795 Billboard(线段树,单点查询)

题目链接: HDU 2795 Billboard 题意: 有个高为h宽为w的墙用于贴宣传海报,每张海报高为1,宽为wi,每张海报在能张贴的情况下优先选择最上面的最左面; 共有n张海报,问贴每张海报所在的行,如果贴不下,就输出-1. 分析; 建立区间为[1,h]的线段树,叶子结点即表示相应层。线段树中存储当前所有层中的最大剩余长度, 查询和更新操作其实放在一起了。 玩玩没想到的是,题目

ramay7 388

hdu 2795 Billboard(线段树)

题目链接:hdu 2795 Billboard 题目大意:有一个n∗m的公告板,一开始为空的,现在每次要想上面贴公告,长度为1∗wi,每次都尽量贴在高的地方。 解题思路:线段树,以每一行为节点建立线段树,n很大,但是q只有20w,所以只要用20w的节点即可。然后每个节点记录区间内的最大值,优先查询左区间。 #include #include #include using na

不慌不忙、不急不躁 681

线段树-hdu2795 Billboard(贴海报)

线段树-hdu2795 Billboard(贴海报) hdu2795 Billboard 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子 思路:每次找到最大值的位子,然后减去L 线段树功能:query:区间求最大值的位子(直接把update的操作在query里做了) 题意:有一块长方形h*w...

weixin_30374009的博客 159

HDU2795 Billboard 线段树

传送门:HDU2795 题意:h*w的木板,放进一些1*L的物品,每次优先放到能容纳且最上边最左边的位子,求每个物品在第几行。 思路:用线段树维护每一行的剩余长度,每次更新时优先询问左子树。代码中我将update和query合到一起了。 代码: #include #include #include #include #include #include #include #include #

WA是一笔财富 293

HDU 2795 Billboard(宣传栏贴公告,线段树应用)

HDU 2795 Billboard(宣传栏贴公告,线段树应用) ACM 题目地址:HDU 2795 Billboard 题意: 要在h*w宣传栏上贴公告,每条公告的高度都是为1的,并且每条公告都要尽量贴最上面最靠左边的,给你一系列的公告的长度,问它们能不能贴上。 分析: 不是非常好想,只是想到了就非常好写了。 仅仅要把宣传栏倒过来就好办了,这时候就...

weixin_30439031的博客 71

HDU2795 Billboard 线段树

题目链接:hdu2795 题意:有一个广告牌大小为h*w。有n个广告,每个广告高度为1,宽度为wi,要把广告贴到广告牌上。要求尽可能往上贴。并输出每个广告贴在第几行,如果不能贴上去则输出-1。 思路:可以用线段树来维护每个区间剩余打最大宽度。初始状态每个点值为w。每次查询的时候,如果左子树最大值大于wi,则往左子树查询,反之往右子树查询。 #include <bits/stdc++.h&gt...

江小举的博客 415

HDU2795 Billboard 线段树 单点更新

Problem DescriptionAt the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are

Bill_Utada的成长之路 1503
上一篇: HDU 1394 Minimum Inversion Number(逆序数)
下一篇: POJ 2418 Hardwood Species(字典树)
RaynX
博客等级 码龄13年 1粉丝 13原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值