Codeforces Round #322 (Div. 2) B. Luxurious Houses 水题
B. Luxurious Houses
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/581/problem/B
Description
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.
Sample Input
5
1 2 3 1 2
Sample Output
3 2 0 2 0
HINT
题意
在一个一维坐标系上有n个house
每个house显得厉害,就是他的楼层要比比他编号大的楼层都要高
然后问你每栋楼至少得加高多少
题解:
扫一遍就好了,其实就是一个查询最大值的过程
@)1%KBO0HM418$J94$1R.jpg)
代码:
//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1205000
#define mod 1000000007
#define eps 1e-9
#define e exp(1.0)
#define PI acos(-1)
#define lowbit(x) (x)&(-x)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* int Max[maxn];
int a[maxn];
int main()
{
int n=read();
for(int i=;i<=n;i++)
a[i]=read();
int tmp = ;
for(int i=n;i>=;i--)
{
Max[i]=tmp+;
tmp = max(tmp,a[i]);
}
for(int i=;i<=n;i++)
printf("%d ",Max[i]>a[i]?Max[i]-a[i]:); }
Codeforces Round #322 (Div. 2) B. Luxurious Houses 水题的更多相关文章
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #357 (Div. 2) B. Economy Game 水题
B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
随机推荐
- Java版本的删除指定目录及子目录下名叫“xxx.txt”的所有文件
以前写过一个python版本的,但是在查找文件路径的时候出现错误,无法正确的获取到文件的路径,就造成无法删除该路径下的“xxx.txt”文件. 当时以为是windows版本系统的错误造成这个问题的,也 ...
- NLog 传递参数
用NLog记文件日志,一般都用{$basedir}变量,把日志记在运行的目录或者它的子目录下,遇到要写在其他目录的下,看了下Nlog找到用环境变量传参数. .net 里写 Environment.Se ...
- TCP编程(七)
此为网络编程的一个系列,后续会把内容补上...
- HTML5 离线功能介绍
HTML5 是目前正在讨论的新一代 HTML 标准,它代表了现在 Web 领域的最新发展方向.在 HTML5 标准中,加入了新的多样的内容描述标签,直接支持表单验证.视频音频标签.网页元素的拖拽.离线 ...
- nopcommerce商城系统--源代码结构和架构
这个文档是让开发者了解nopcommerce解决方案结构的指南.这是新的nopcommerce开发者学习nopcommerce代码的相关文档.首先,nopCommerce源代码是很容易得到的.它是一个 ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.7
Prove that for any vectors $$\bex u_1,\cdots,u_k,\quad v_1,\cdots,v_k, \eex$$ we have $$\bex |\det(\ ...
- 用pip爽久了,竟然完了easy install安装过程了
新换了mac,装python环境时才发现,一直用pip,反而忘了easy_install的安装方法了.这里记录一下: 1.下载ez_install.py文件:https://bootstrap.pyp ...
- ubuntu12.04 安装 chrome
1.下载deb包 2. sudo apt-get remove google-chrome-stable sudo dpkg -i google-chrome-stable_current_amd64 ...
- STM32 串口功能 库函数 详解和DMA 串口高级运用(转载)
数据传输时要从支持那些相关的标准?传输的速度?什么时候开始?什么时候结束?传输的内容?怎样防止通信出错?数据量大的时候怎么弄?硬件怎么连接出发,当然对于stm32还要熟悉库函数的功能 具起来rs232 ...
- Codeforces Round #355 (Div. 2)
A 弯腰 #include<cstdio> #include<cstring> #include<iostream> #include<queue> # ...