Codeforces 625B Luxurious Houses【思维】

网络安全 —— 实验(基于华为eNSP模拟器) 8. 实验八 —— 通过路由的远程管理(基于实验七的基础配置)8. 实验八 —— 通过路由的远程管理(基于实验七的基础配置)6. 实验六 —— 交换机的远程控制(直接控制和间接控制)6. 实验六 —— 交换机的远程控制(直接控制和间接控制)5. 实验五 —— 将交换机作为PC端通过交换机相连。5. 实验五 —— 将交换机作为PC端通过交换机相连。4. 实验四 —— 两个PC机通过两台交换机相连。2. 实验二 —— 两个PC机通过交换机相连。2. 实验二 —— 两个PC机通过交换机相连。 阅读详情

B. Luxurious Houses
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.

Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.

The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.

Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

Input

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland.

The second line contains n space-separated positive integers hi (1 ≤ hi ≤ 109), where hi equals the number of floors in the i-th house.

Output

Print n integers a1, a2, ..., an, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero.

All houses are numbered from left to right, starting from one.

Examples
input
5
1 2 3 1 2
output
3 2 0 2 0 
input
4
3 2 1 4
output
2 3 4 0 

题目大意:

一共给你N个楼的高度,设定一个luxurious楼,表示这个楼严格要与他右边的所有的楼。

问如果我们想要设定第i个楼为luxurious楼,那么对应最少需要加多少楼层。


思路:


正序判断O(n^2)超时肯定是会TLE的,我们对应这个楼想要变成luxurious楼,肯定是要比他后边所有的楼都高才行。

那么对应我们只要维护出当前位子后边最高的楼的层数即可。

所以我们直接从后边向前扫,逆序处理这个问题即可,时间复杂度O(n^2)


Ac代码:


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int ans[100600];
int a[100600];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        int maxn=0;
        for(int i=n-1;i>=0;i--)
        {
            if(i==n-1)
            {
                ans[i]=0;
                maxn=max(maxn,a[i]);
                continue;
            }
            if(maxn==a[i])
            {
                ans[i]=1;
            }
            else if(a[i]>maxn)
            {
                ans[i]=0;
                maxn=a[i];
            }
            else
            {
                ans[i]=maxn-a[i]+1;
            }
        }
        for(int i=0;i<n;i++)
        {
            printf("%d ",ans[i]);
        }
        printf("\n");
    }
}




MFC IP Address Control 使用详解:从基础到高级应用 本文详细介绍了MFC中IPAddressControl控件的使用方法,包括基础创建、属性配置、样式自定义和高级功能实现。主要内容涵盖:控件初始化、默认IP设置、外观修改、派生类创建、消息处理、批量管理以及常见问题解决方案。通过示例代码展示了如何验证IP范围、优化性能和处理键盘输入等实用技巧,为开发网络应用程序提供了专业指导。文章还给出了多个备选标题,适合不同层次开发者参考使用。 阅读详情

相关推荐

idea 编译打包nacos2.0.3源码,生成可执行jar 包常见问题

idea 编译打包nacos2.0.3源码,生成可执行jar 包常见问题

fyihdg的专栏 1226

CodeForces - 625B War of the Corporations( kmp )

题目链接:点击进入 题目 题意 问在文本串中至少修改几个字母可以使模式串不再在文本串中出现。 思路 与此题类似 实际上求的就是模式串在文本串中出现多少次,要求匹配的子串不能有交集,那么只需要在匹配成功后模式串上的指针 j 不在变成 next [ j ] ,而是从 0 开始就行。 代码 // Problem: Oulipo // Contest: Virtual Judge - POJ // URL: https://vjudge.net/problem/POJ-3461 // Memory Limit:

Cosmic_Tree的博客 378

Android手机本地语音转文字实战:用FunASR+ONNX Runtime打造离线ASR应用(附模型下载)

本文详细介绍了如何在Android应用中集成FunASR和ONNX Runtime,构建高性能的离线语音识别系统。通过模型选择、工程化集成和性能调优等实战技巧,开发者可以实现本地语音转文字功能,有效保护用户隐私并提升响应速度。

weixin_29046611的博客 274

Codeforces - 625B 贪心

求最小不重复匹配次数 改最后一个字符最划算 我当时怎么就没看出来.. #include<bits/stdc++.h> using namespace std; string S,T; int main(){ while(cin>>S>>T){ int ans=0; for(int i = 0; i < S.lengt...

weixin_30666753的博客 140

TSmaster CANFD配置避坑指南:为什么你的PCAN盒不支持最新版本?

本文针对TSmaster配置PCAN硬件进行CANFD通信时的常见问题,提供了详细的避坑指南。重点解析了CANFD配置中TSEG1等关键参数的理解误区,并深入探讨了TSmaster新版本与PCAN硬件驱动之间的兼容性变化,帮助工程师快速定位并解决连接失败或无法发送CANFD报文等问题。

alpha的博客 554

贝叶斯机器学习在吸附量预测中的应用

本文介绍了贝叶斯机器学习在吸附量预测中的应用。通过Python实现完整的贝叶斯建模流程,包括数据生成、预处理、模型构建与评估。文章对比了贝叶斯与频率学派的差异,详细阐述了贝叶斯线性回归和神经网络的实现方法,并提供了数据可视化、模型诊断等技术细节。该方法不仅能预测吸附量,还能量化预测不确定性,为工程决策提供更全面的依据。全文超过6000字,结合理论推导与代码实践,是应用贝叶斯方法解决实际工程问题的完整指南。

AI的内部世界的博客 172

cf 581 B.Luxurious Houses

B. Luxurious Houses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The capital of Berland has n multifloor

乱齐八糟 553

Python学习第32天:Web前端入门

本文介绍了Web前端开发三大核心技术:HTML、CSS和JavaScript。首先概述了HTML的发展历程和HTML5新特性,详细讲解了常用HTML标签如文本、列表、链接、图像、表格、表单等。其次介绍了CSS的基础语法、选择器、颜色字体设置、盒子模型和布局定位方法。最后简要提及JavaScript为网页添加交互功能的作用。文章为Python开发者提供了前端技术的基础知识,帮助理解网页的结构、样式和行为实现原理。

tigerhhzz的博客 1920

codeforces 625B KMP水题

题意:给定一个模板串,问该字符串在文本串出现的次数。 KMP算法水过。。 代码如下: #include #include #include using namespace std; const int maxn = 1e5+10; char text[maxn],p[maxn]; int Next[maxn]; int len; int ans; void get_next

勇敢前进的ACMer 496

21天学会基于 Linux 的 NPU 固件开发--2.2 固件加载流程:request_firmware() 深度解析

本文深度解析Linux内核中NPU固件加载流程,重点剖析request_firmware()机制。内容涵盖:1)内核态与用户态的交互机制,包括同步/异步加载方式;2)NPU固件的特殊格式与加载逻辑;3)调试技巧与安全验证方案;4)提供最小化固件加载器实验。文章揭示了从文件系统到硬件初始化的完整链路,探讨了大模型时代面临的性能挑战与优化方案,如零拷贝加载技术,并提出了版本兼容性、断电恢复等关键问题的思考方向。

amy_mhd的博客 63

【100%通过率】华为OD机试真题 Python 实现【最多组合直角三角形个数】【2023 Q1 | 100分】

有N条线段,长度分别为a[1]-a[n]。 现要求你计算这N条线段最多可以组合成几个直角三角形。 每条线段只能使用一次,每个三角形包含三条线段。

MISAYAONE的博客 1万+

G - G CodeForces - 625B(贪心)

G - G CodeForces - 625B(贪心) A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol ...

做一只熊猫不好吗? 271

捷联惯导,其实没有你想象的那么复杂!(附:惯导嵌入式应用中需要的一些C代码)

摘要:捷联惯导系统将惯性测量单元固连于运动载体,通过核心算法实现导航解算。系统首先进行传感器误差补偿和初始对准,然后利用陀螺和加速度计数据,通过姿态更新算法(如四元数法)计算载体相对于地理系的姿态。加速度数据经比力方程转换后积分得到速度和位置,过程中需补偿圆锥误差和划船效应。捷联惯导通过数字平台替代物理平台,实现了载体坐标系与导航坐标系的实时转换,是当前惯性导航系统的主流方案。

victoryqian528的博客 274

Luxurious Houses(模拟)

B. Luxurious Houses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The capital of Berland has n multifloor

梧桐下的四叶草 528

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

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

Codeforces 625B【KMP】

题意就是一个串在另一个串出现几次,但是字符不能重复匹配, 比如aaaaaaaaaaa的答案是1 思路: 本来写了个暴力过的,然后觉得KMP改改就好了,就让队友打了一个; #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAX=1000010; int n,m; ...

weixin_30685047的博客 205

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Codeforces 394A Counting Sticks(水题)

题目链接:Codeforces 394A Counting Sticks 题目大意:给出一个由木棍组成的式子,要求移动最多一个木棍,使得式子为等式。 解题思路:水题,注意加数和和都不可以为0. #include #include const int N = 505; char str[N]; int a, b, c, s; void init() { get

不慌不忙、不急不躁 1019

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

(514B)codeforce

B. Han Solo and Lazer Gun time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n Imperial stormtroopers

Amon 553

CodeForces - 1266D

Decreasing Debts There are n people in this world, conveniently numbered 1 through n. They are using burles to buy goods and services. Occasionally, a person might not have enough currency to buy what...

ZzzzGgggHhhh的博客 312

CodeForces 625 B. War of the Corporations(水~)

Description 给出两个串a和b,问a最多可以拆出几个b Input 两个字符串a和b,a串串长不超过100000,b串串长不超过30 Output 输出a串最多可以拆成几个b串 Sample Input sirisiri sir Sample Output 2 Solution 简单题,暴力扫一遍即可 Code#include<iostream> #include

ZSQ 956

CF#322-B. Luxurious Houses-模拟水题

n个房子在一列上,每个房子有高度值  定义: 如果房子i的高度比右边所有房子都高,则 为  高贵的房子 求出对每一个房子,要使得自己变成高贵的房子需要增加多少高度 直接预处理右边所有房子高度最大值即可。 最后输出比较是 右边所有房子的max_high大 还是自己大就可以了 水题 #include #include #include #include #inclu

缺氧 634

Codeforces Round #318 574B Bear and Three Musketeers(模拟)

B. Bear and Three Musketeers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Do you know a story about the

GKHack's Blog 1360

codeforces 549D D. Haar Features(枚举)

题目链接: 点击打开链接 题目大意: 给出你一个矩阵,然后你只能从左上角起用一个矩形将围出的部分修改,问修改成指定样子需要多少步 题目分析: 这道题就是最最恶心的英语题,题看懂了一切都迎刃而解 主要就是枚举与当前点与右下角的曼哈顿距离,然后枚举满足这个距离的点集,作为右下角进行矩形染色,因为他们都是互不影响的,如果他们当前的颜色就是合法颜色,那么跳过,依次类推,染到左上角就好了,最坏复

llin-黎辰 1163

Codefoeces 581B Luxurious Houses

要求求出每个数后面的数的最大值比这个数大多少。#include<cstdio> #include<iostream> using namespace std; #define MAXN 100005 int a[MAXN], n, ans[MAXN]; int main() { scanf("%d", &n); for(int i = 1; i <= n; i ++)

geng4512的专栏 1319

B. Luxurious Houses

每个数 a[i] 加多少比他右边的所有数都严格大 const int N=2e5+5; int n,m,t; int i,j,k; int a[N]; vector<int> ans; int main() { IOS; for(;cin>>n;){ for(i=1;i<=n;i++) cin>>a[i]; int maxx=-1; for(i=n;i;i..

C_Dreamy的博客 409

CodeForces 919B(枚举)

题目链接:点击打开链接题目大意:输入一个k,找到第K个满足各位相加等于10的数字 题目思路:纸上写一下就会发现前一百每个数字之间隔9,然后过了100以后有时候会隔9不满足,但是没关系,check一下就好了 以下是代码:#include&lt;iostream&gt; #include&lt;cstdio&gt; using namespace std; bool check(int x){ in...

smilestruggler_Fly To Higher 420

水题

Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome...

jude的博客 327
上一篇: Codeforces 546C Soldier and Cards【模拟】【期末考试全突击啊T T 】
下一篇: 51nod 1414 冰雕【思维+暴力】
mengxiang000000
博客等级 码龄11年 627粉丝 2116原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值