Codeforces Round #322 B Luxurious Houses
题意: 给出你N个数,问你这个数想要比后面的数都大至少要加几?
思路: 有一点点考思路,从后向前找,依次找出最大值,直接比较就可以了,有一点点细节,就是要记录最大数和当前数的下标是否是同一位置,如果是则为0否则,直接算便可、
AC代码:
#include<cstdio>
#include<cstring>
const int maxn=100100;
int a[maxn];
int b[maxn];
int n;
int main()
{while(scanf("%d",&n)!=EOF){for(int i=0;i<n;i++)scanf("%d",&a[i]);int x=0; int y;for(int i=n-1;i>=0;i--){if(x<a[i]){x=a[i];y=i;}if(y==i)b[i]=x-1;else b[i]=x;}for(int i=0;i<n-1;i++){if(b[i]>=a[i])printf("%d ",b[i]-a[i]+1);elseprintf("0 ");}printf("0\n");}return 0;
}
Codeforces Round #322 B Luxurious Houses相关推荐
- 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 ...
- CodeForces - 581B - Luxurious Houses 逆序处理水
题目链接: http://codeforces.com/problemset/problem/581/B B - Luxurious Houses CodeForces - 581B 题目大意: 给一 ...
- CodeCraft-21 and Codeforces Round #711 (Div. 2)
CodeCraft-21 and Codeforces Round #711 (Div. 2) 题号 题目 考点 A GCD Sum 签到,模拟 B Box Fitting 贪心 C Planar R ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
- Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)
Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- Codeforces Round #270
Codeforces Round #270 题目链接 A:我是筛了下素数.事实上偶数仅仅要输出4和x - 4,奇数输出9和x - 9就可以 B:贪心的策略,把时间排序后.取每k个的位置 C:贪心.每次 ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
最新文章
- 一文搞懂select语句在MySQL中的执行流程!
- R语言配置可视化内容中的字体为斜体(italic)实战:标题斜体、轴标签斜体、文本内容斜体、或者部分内容斜体
- 美国女生给我的六个惊诧
- 安全的交互通道 及 栈回塑检查与伪造
- 课时 21:Kubernetes 存储架构及插件使用(阚俊宝)
- Django开发准则与最佳实践
- 台式电脑已连接但无法上网_电脑无法上网?五步帮你解决!
- 生产力提升! 自己动手自定义Visual Studio 2019的 类创建模板,制作简易版Vsix安装包...
- hive2 mysql_架构hive2mysql流程
- 五年烧光 3.5 亿美金,互联网独角兽是如何把自己玩死的?
- zabbix客户端安装配置
- php 高并发接口,接口高并发解决方案
- java 生成高清缩略图_java生成高清缩略图
- 不要等到双十一,MathType公式编辑器提前降价!
- 比特bit,字节Byte,带宽流量和流速的关系,存储容量单位
- Snagit 2019 快速截图
- 【esp8266】【Node.js】【Websocket】esp8266和Node.js通过websocket进行通信,实验记录及踩坑记录
- 感知机算法在鸢尾花数据集上的实践
- linux启动、进程、文本处理
- FASTQ文件详解【转】