题目:

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

Input
51 2 3 1 2

Output
3 2 0 2 0 

Input
43 2 1 4

Output
2 3 4 0题意: (这道题开始并没有看懂题目意思,后开看别人的才知道)题目不难,想想可以做      给你一个数你,表示接下来n个输入,接下来的n个数表示每个房子的楼层数,其中最右边的和这组数中最大的为豪华住宅,问你每个住宅加几层可以成为豪华住宅,就是说     每个住宅的层数都要比右边的大分析:   应为每个住宅都要是豪华的,且都各自独立,所以我们从这组数的末尾开始遍历,开两数组,一个储存原来的信息,另一个记录当前值与最大值的关系,即我判断如果当前值大于最大值              记录下来这个形式,当前值等于最大值再记录,当前值小于最大值,用数组也记录下来,最后再循环,判断原数组与记录数组间的关系,比较判断就OK了。。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=100001;
 6 int a[maxn],b[maxn];
 7 int main()
 8 {
 9     int n;
10     cin>>n;
11     for(int i=0;i<n;i++)
12         cin>>a[i];
13     int Max=0;
14     for(int i=n-1;i>=0;i--)
15     {
16         if(a[i]>Max) b[i]=a[i];
17         else if(a[i]==Max) b[i]=0;
18         else
19             b[i]=Max;
20         Max=max(Max,a[i]);
21     }
22     for(int i=0;i<n-1;i++)
23     {
24         if(b[i]==a[i]) printf("0 ");
25         else if(b[i]==0) printf("1 ");
26         else
27             printf("%d ",b[i]-a[i]+1);
28     }
29     printf("0\n");
30     return 0;
31 }

View Code

转载于:https://www.cnblogs.com/forwin/p/4855165.html

cf 581B-------Luxurious Houses相关推荐

  1. CodeForces - 581B - Luxurious Houses 逆序处理水

    题目链接: http://codeforces.com/problemset/problem/581/B B - Luxurious Houses CodeForces - 581B 题目大意: 给一 ...

  2. Codefoeces 581B Luxurious Houses

    要求求出每个数后面的数的最大值比这个数大多少. #include<cstdio> #include<iostream> using namespace std; #define ...

  3. codeforces 581B Luxurious Houses(线段树点更新,区间查询)

    题目链接: http://codeforces.com/problemset/problem/581/B 题目大意: 给n个不同高度的房子,要求当对于第i个房子来说,他要严格的比后面的房子都高. 思路 ...

  4. CF581B Luxurious Houses 模拟

    CF581B Luxurious Houses 模拟 The capital of Berland has n multifloor buildings. The architect who buil ...

  5. Codeforces Round #322 (Div. 2) B. Luxurious Houses 水题

    B. Luxurious Houses Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/pr ...

  6. Luxurious Houses - CodeForces - 581B

    題目鏈接 本題屬於簡單的implementation. 有 nn 個房子,編號從左到右依次是 1→n1\to n,每個房子有 a[i]a[i] 級臺階. 定義若這個房子的臺階數「嚴格大於」右邊所有房子 ...

  7. 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 ...

  8. 【Henu ACM Round#19 B】 Luxurious Houses

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 从右往左维护最大值. 看到比最大值小(或等于)的话.就递增到比最大值大1就好. [代码] #include <bits/std ...

  9. CF581B Luxurious Houses

    题目大意是给定了一排房子的高度,定义一个概念,当某一幢房子的高度比它右边(即编号比它大的)所有房子层数都要多时,我们便说它是豪华的房子.问题是若第i幢房子是豪华的,则它需要再增加多少层?并以一个数列的 ...

  10. Codeforces Round #322 B Luxurious Houses

    题意: 给出你N个数,问你这个数想要比后面的数都大至少要加几? 思路: 有一点点考思路,从后向前找,依次找出最大值,直接比较就可以了,有一点点细节,就是要记录最大数和当前数的下标是否是同一位置,如果是 ...

最新文章

  1. 5.3Role和Claims授权「深入浅出ASP.NET Core系列」
  2. IT界程序员几大恶习能立即让你变穷,你有吗?
  3. 《JavaScript语言精髓与编程实践》读书笔记二
  4. 分享一下spark streaming与flume集成的scala代码。
  5. DM365视频处理流程/DM368 NAND Flash启动揭秘
  6. Cheatsheet: 2010 12.13 ~ 12.23
  7. java.policy无法修改_如何配置Policy文件进行Java安全策略的设置
  8. 福建省高等学校非计算机考试大纲,福建省高等学校计算机应用水平等级考试三级(偏软)考试大纲...
  9. 用代码证明自己闲的蛋疼(一)——cmd闪瞎狗眼
  10. Zookeeper 安装部署
  11. 算法导论 思考题4-1
  12. teamview linux命令行安装参数
  13. 做了三年前端开发后,我选择回家创业
  14. 计算机怎么禁用软件网络访问,Windows10系统下禁止软件联网的两种方法
  15. aliddns ipv6_利用阿里云ddns动态解析ipv6地址
  16. 事务Transaction的理解(一)
  17. 温故而知新,可以为师矣,回忆一下排序的思路
  18. gis统计百分比_详细讲解ArcGIS数据统计及字段计算
  19. 如何确定Kmeans中的k值
  20. 以悠悠之生,立一技之长,而贞静自守

热门文章

  1. 【web前端特效源码】使用HTML5+CSS3+JavaScript制作一个复古手机键盘(带声音)的动画效果~~适合初学者~超简单~
  2. 桌面的「微信」坏了,「如何恢复」
  3. matlab失明的小猫,如何正确判断猫咪眼睛是否失明
  4. 锁相环载波同步MATLAB实现,利用锁相环实现载波同步
  5. 【离散数学】点割集(割点集)与边割集详解
  6. excel中按出生日期排序公式
  7. HDU 2111 JAVA
  8. 微信小程序:map组件所在页面加载慢,长时间白屏的问题
  9. android友盟微信授权登录清除,【转载】Android友盟SDK微信授权登录接入
  10. 基于全基因组的基因家族分析的初尝试