CF581B Luxurious Houses 模拟
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).
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.
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.
- 5
1 2 3 1 2
- 3 2 0 2 0
- 4
3 2 1 4
- 2 3 4 0
dp[ i ] 表示从 I 位置到尾的区间最大值;
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstdlib>
- #include<cstring>
- #include<string>
- #include<cmath>
- #include<map>
- #include<set>
- #include<vector>
- #include<queue>
- #include<bitset>
- #include<ctime>
- #include<deque>
- #include<stack>
- #include<functional>
- #include<sstream>
- //#include<cctype>
- //#pragma GCC optimize(2)
- using namespace std;
- #define maxn 1000005
- #define inf 0x7fffffff
- //#define INF 1e18
- #define rdint(x) scanf("%d",&x)
- #define rdllt(x) scanf("%lld",&x)
- #define rdult(x) scanf("%lu",&x)
- #define rdlf(x) scanf("%lf",&x)
- #define rdstr(x) scanf("%s",x)
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int U;
- #define ms(x) memset((x),0,sizeof(x))
- const long long int mod = 1e9 + 7;
- #define Mod 1000000000
- #define sq(x) (x)*(x)
- #define eps 1e-4
- typedef pair<int, int> pii;
- #define pi acos(-1.0)
- //const int N = 1005;
- #define REP(i,n) for(int i=0;i<(n);i++)
- typedef pair<int, int> pii;
- inline ll rd() {
- ll x = 0;
- char c = getchar();
- bool f = false;
- while (!isdigit(c)) {
- if (c == '-') f = true;
- c = getchar();
- }
- while (isdigit(c)) {
- x = (x << 1) + (x << 3) + (c ^ 48);
- c = getchar();
- }
- return f ? -x : x;
- }
- ll gcd(ll a, ll b) {
- return b == 0 ? a : gcd(b, a%b);
- }
- int sqr(int x) { return x * x; }
- /*ll ans;
- ll exgcd(ll a, ll b, ll &x, ll &y) {
- if (!b) {
- x = 1; y = 0; return a;
- }
- ans = exgcd(b, a%b, x, y);
- ll t = x; x = y; y = t - a / b * y;
- return ans;
- }
- */
- int n;
- int h[maxn];
- int a[maxn];
- int dp[maxn];
- int main() {
- //ios::sync_with_stdio(0);
- rdint(n);
- for (int i = 1; i <= n; i++)rdint(h[i]);
- dp[n] = h[n]; int maxx = h[n];
- for (int i = n; i >= 1; i--) {
- maxx = max(maxx, h[i]);
- dp[i] = maxx;
- // cout << dp[i] << endl;
- }
- for (int i = 1; i <= n; i++) {
- if (i == n) {
- cout << 0 << endl; return 0;
- }
- if (h[i] > dp[i+1])cout << 0 << ' ';
- else {
- cout << dp[i+1] - h[i] + 1 << ' ';
- }
- }
- return 0;
- }
CF581B Luxurious Houses 模拟的更多相关文章
- cf581B Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...
- CF581B Luxurious Houses 题解
Content 一条大街上有 \(n\) 个房子,第 \(i\) 个房子的楼层数量是 \(h_i\).如果一个房子的楼层数量大于位于其右侧的所有房屋,则房屋是豪华的.对于第 \(i\) 个房子,请求出 ...
- 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 ...
- Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...
- 【Henu ACM Round#19 B】 Luxurious Houses
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 从右往左维护最大值. 看到比最大值小(或等于)的话.就递增到比最大值大1就好. [代码] #include <bits/std ...
- Codeforces Round #322 (Div. 2)
水 A - Vasya the Hipster /************************************************ * Author :Running_Time * C ...
- Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心
A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces Round #408 (Div. 2)(A.水,B,模拟)
A. Buying A House time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- HDU 5538 House Building(模拟——思维)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5538 Problem Description Have you ever played the vi ...
随机推荐
- list()的相关问题
由php手册中可以看到对list的定义: list — 把数组中的值赋给一些变量,像 array() 一样,这不是真正的函数,而是语言结构.list() 用一步操作给一组变量进行赋值. array l ...
- wamp集成环境下mysql数据库的分开部署和远程访问
今天折腾了一天一个小问题,就是明明正确的php代码在访问数据库的时候总是提示DB ERROR.后来才发现是填写数据库名的时候,写成了该数据库的ip地址(其实也是本机ip但是本机还是不能访问),而不是l ...
- javascript的概述
JavaScript是怎么诞生的???刚开始的是为了验证表单而开发出来的. 什么是JavaScript???a.面向对象的编程语言b.解释性的编程语言(说白了就是不用编译的一种语言)c.脚本语言(说白 ...
- ssh框架整合其他方式(没有hibernate核心配置文件)
- 第4章_Java仿微信全栈高性能后台+移动客户端
基于web端使用netty和websocket来做一个简单的聊天的小练习.实时通信有三种方式:Ajax轮询.Long pull.websocket,现在很多的业务场景,比方说聊天室.或者手机端onli ...
- Nginx --Windows下和Linux下搭建集群小记
nginx: Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器 特点: 反向代理 负载均衡 动静分离... 反向代理 : 先来了解正向代理:需要我们用户 ...
- 百度Apollo解析——0.使用VSCode编译Apollo项目
1.安装微软Visual Studio Code 1.1 方法一 开始之前,首先需要安装Ubuntu Make.虽然Ubuntu Make存在Ubuntu15.04官方库中,但是需要Ubuntu Ma ...
- Struts2框架05 result标签的类型、拦截器
1 result标签是干什么的 就是结果,服务器处理完返回给浏览器的结果:是一个输出结果数据的组件 2 什么时候需要指定result标签的类型 把要输出的结果数据按照我们指定的数据类型进行处理 3 常 ...
- TaikrSpaceShooterStartKit.unitypackage包下载地址
有好多教程里面没有资源包,现在加密分享给大家 unity4.* 链接: https://pan.baidu.com/s/1XMo2zVpV3ZhkNZKOb6H0yw 密码: tqnt unity5 ...
- LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
reinterpret_cast代表强制转化,即把pNMHDR强制转化成LPNMITEMACTIVATE类型的. reinterpret_cast<type-id> (expression ...