Two Buildings
Two Buildings
Write a program that, given a sequence of building heights, prints max1≤i<j≤n(hi+hj)∗(j−i).
Input
5
1 3 2 5 4
Output
21
Input
5
8 3 6 3 1
Output
36
解析:对于任意i,j 若存在k>j并且h[k]>h[j]则j不可能是我们想要的右界,可以把他排除,同理也可以对左界进行排除,然后左界的数据和右界的数据进行配对找出最大值
对于(hi+hj)∗(j−i)等于(hi-(-hj))∗(j−i)可以表示成一个矩形的面积
而对于左右界的数据来说:先去中间值mid再右侧找到使结果最大的pos点,对于mid左侧的数据来说(右侧同理)
图片转自https://www.cnblogs.com/wjyyy/p/CF102920L.html
所以只需要找到mid和pos配对 以及mid左侧的点和pos及左侧进行配对,以及mid右侧的点和pos及右侧的点进行配对
AC代码:
#include<iostream>
using namespace std;
int a[1000010];
int zz[1000010][2];
int yy[1000010][2];
int conz=0,cony=0;
long long ans=0;
long long jc(int x,int y)
{return 1LL*(zz[x][0]+yy[y][0])*(yy[y][1]-zz[x][1]);
}
void fact(int l1,int r1,int l2,int r2)
{int mid=l1+r1>>1;int pos=l2;for(int i=l2;i<=r2;i++)if(jc(mid,i)>jc(mid,pos))pos=i;ans=max(ans,jc(mid,pos));if(mid-1>=l1) fact(l1,mid-1,pos,r2);if(mid+1<=r1) fact(mid+1,r1,l2,pos);
}
int main()
{int n;cin>>n;for(int i=1;i<=n;i++) scanf("%d",a+i);int pos1=0,pos2=0;for(int i=1;i<=n;i++){if(a[i]>pos1) pos1=a[i],zz[++conz][0]=a[i],zz[conz][1]=i;if(a[n-i+1]>pos2) pos2=a[n-i+1],yy[++cony][0]=a[n-i+1],yy[cony][1]=n-i+1;}fact(1,conz,1,cony);cout<<ans<<endl;
}
Two Buildings相关推荐
- 2015 Multi-University Training Contest 2 1002 Buildings
Buildings Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5301 Mean: n*m列的网格,删除一个格子x,y,用矩 ...
- Shortest Distance from All Buildings
Shortest Distance from All Buildings 题目链接:https://leetcode.com/problems... 这道题要求最短的距离,一般这种要求可以到的地方的距 ...
- LTE Module User Documentation(翻译5)——Mobility Model with Buildings
LTE用户文档 (如有不当的地方,欢迎指正!) 8 Mobility Model with Buildings 我们现在通过例子解释如何在 ns-3 仿真程序中使用 buildings 模型(特别是 ...
- HDU4372 Count the Buildings
HDU4372 Count the Buildings 题目描述 Solution 思路很妙. 考虑从最高的一个楼房将序列分开,左边可以看到FFF个,右边可以看到BBB个,一个楼房可以被看到,则一定是 ...
- LeetCode Shortest Distance from All Buildings
原题链接在这里:https://leetcode.com/problems/shortest-distance-from-all-buildings/ 题目: You want to build a ...
- 【Paper】Short Term Electric Energy Consumption Prediction in in Smart Buildings Methods Survey
论文原文:点击此处 论文年份:2019 论文被引:10(2020/08/06/) 43(2022/03/26) 文章目录 A Comparative Study of Time Series Fore ...
- Learn from Architects of Buildings
 Learn from Architects of Buildings Keith Braithwaite Architecture is a social act and the material ...
- 2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
linkkkkkk 题意: 给定长度为nnn的数组ccc,求max((j−i)∗(ci+cj))max((j-i)*(c_i+c_j))max((j−i)∗(ci+cj)) 思路: 将式子转化为m ...
- 《Energy and Buildings》期刊介绍(SCI 2区)
期刊官方网站 期刊投稿网址 期刊投稿小助手 介绍 Energy and Buildings is an international journal publishing articles with e ...
- Google Earth Engine(GEE)——全球建筑物矢量图免费下载Open Buildings V1 Polygons
之前我们已经介绍过了关于微软全球建筑物提取的矢量图. 全球建筑物提取数据集(免费下载):微软/GlobalMLBuildingFootprints_此星光明2021年博客之星云计算Top3的博客-CS ...
最新文章
- 【Luogu】P3927 SAC E#1 - 一道中档题 Factorial
- java web 监控cpu、内存等。hyperic-sigar
- 红管2不显示服务器,红色管弦乐队2怎么建立服务器 | 手游网游页游攻略大全
- C++ Linux下线程池的实现
- 【GIT】使用Git命令窗口将本地工程提交至远程GitHub
- Nginx 基础 ( 二)
- lgg6可以root的版本_Kali Linux 2020.1版本变更内容
- 完美世界2020编程题-救雅典娜 英雄AB PK
- PL/SQL Developer Initialization erro
- oracle mysql认证考试流程_报考oraclemysql认证考试流程有些什么步骤
- 学校做计算机教室锐捷,锐捷“云课堂”:先改变桌面云,再改变教室
- 蓝桥杯——摔手机 动态规划
- 翻译 Duckietown an Open, Inexpensive and Flexible Platform for Autonomy Education and Research
- 阿里巴巴Java成神之路-笔记(8)动态代理
- 15、Spark_RDD算子——AggregateByKey
- BZOJ 4892: [Tjoi2017]DNA(SA+RMQ / SAM)
- 三大运营商最新的手机号段分配情况
- 徕卡 sl android app,随时随地无缝互联 徕卡发布最新版FOTOS App
- 年薪50万的程序员_毕业之后,这些年薪50万+的90后程序员经历了什么?-阿里云开发者社区...
- OpenMVG、OpenMVS配置及学习记录(Win10+VS2015)
热门文章
- dxf制作kml_如何导入矢量边界文件,kml shap.dxf 格式
- RepVGG:让VGG风格的ConvNet再次伟大起来
- python识别图片内容并获取两个地点间的距离
- 深度解读达芬奇架构:华为AI芯片的“秘密武器”
- Sublime Text常用快捷键及插件配置
- 数字IC验证:总线握手协议(VALID/READY握手机制)
- 记事本-java课程设计_java课程设计----记事本
- 【原创理论】 数据处理•数据沉淀法则
- php无极限分类讲解,php无限极分类入门教程
- Linux i2c总线(2) - I2C核心层