我是靠谱客的博主 小巧菠萝,最近开发中收集的这篇文章主要介绍CF#322-B. Luxurious Houses-模拟水题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

n个房子在一列上,每个房子有高度值 

定义: 如果房子i的高度比右边所有房子都高,则 为  高贵的房子

求出对每一个房子,要使得自己变成高贵的房子需要增加多少高度

直接预处理右边所有房子高度最大值即可。

最后输出比较是 右边所有房子的max_high大 还是自己大就可以了


水题


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
 
__int64 min(__int64 a,__int64 b)
{
	return a<b?a:b;
}
 
__int64 max(__int64 a,__int64 b)
{
	return a>b?a:b;
}

__int64 tm[100005];
__int64 need[100005];
int main()
{

	__int64 a,b;
	__int64 n;
	scanf("%I64d",&n);
	__int64 i;
for (i=1;i<=n;i++)
{
	scanf("%I64d",&tm[i]); 
}
need[n]=0;
for (i=n-1;i>=1;i--)
{
	if (tm[i+1]>need[i+1])
		need[i]=tm[i+1];
	else
		need[i]=need[i+1];
}

for (i=1;i<=n;i++)
{
	if (i!=1) printf (" ");

	if (tm[i]>need[i])
		printf("0");
	else
		printf("%I64d",need[i]-tm[i]+1);
}
printf("n");
 


最后

以上就是小巧菠萝为你收集整理的CF#322-B. Luxurious Houses-模拟水题的全部内容,希望文章能够帮你解决CF#322-B. Luxurious Houses-模拟水题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部