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 ...
随机推荐
- MSSQL复制功能实现与Oracle数据库同步
1.分别建立链接对数据库进行操作,SQLServer可以用ADO.NET,操作Oracle可以用OLEDB或者用System.Data.OracleClient(需要添加引用才能用) 这种方案的优点就 ...
- win设置壁纸
默认壁纸图片位置: C:\Windows\Web\Wallpaper\Scenes 你可以自己建文件夹,放自己喜欢的桌面壁纸. 设置壁纸: 桌面右键 -> 个性化 然后点击 “桌面背景” - ...
- js标点符号全局匹配
var modelCode = node.modelCode.replace(/\./g, '\_'); 注意后面的 "\" <script language=" ...
- 8.11-8.16:usaco
summary:57 bzoj1741:裸二分图最大匹配 #include<cstdio> #include<cstring> #include<iostream> ...
- PHP Fileinfo组件越界内存破坏漏洞
漏洞版本: PHP PHP 5.x 漏洞描述: BUGTRAQ ID: 66002 CVE(CAN) ID: CVE-2014-2270 PHP是一种HTML内嵌式的语言. PHP的file程序在解析 ...
- tyvj1161聚会的名单(trie树)
背景 Background 明天就是candy的生日,candy又会邀请自己的一大堆好友来聚会了!哎!又要累坏飘飘乎居士了!! 描述 Description 明天就是candy的生日.晚上,c ...
- Vs 引用第三方DLL文件 版本不一致问题 (npoi与memcached中的ICSharpCode.SharpZipLib版本冲突的解决方案)
最近在 做 MailChimp 与网站功能 集成时,发现 MailChimp 2API 中的 MailChimp.dll 中的依赖项 SerivceStack.Text.dll (版本为3.9.71 ...
- SQL Server AlwaysOn 和 ILB
Narayan Annamalai 网络高级项目经理 自 2013 年 8 月起,Azure 基础结构服务开始支持 SQL ServerAlwaysOn 可用性组.Azure 服务的内部负载平衡 (I ...
- matlab mex入门简介
mex 的目的 通过C/C++语言编写代码,在Matlab中将其编译成mex文件主要可以做以下几方面的事情: 1.加快程序的执行速度. Matlab在for上如老牛拉车的速度确实让人抓狂. 2.将Ma ...
- hbase shell下如何使用删除键
今天刚安装好了hbase,通过Secure CRT登录hbase shell,敲入错误命令无法使用删除键(Backspace或是Ctrl+Backspace都不管用)删除,后来在终端-->仿真下 ...