Two Buildings

Zynq远程更新程序实战:从emmc到flash的完整方案解析 本文详细解析了Zynq远程更新程序的完整方案,重点探讨了从emmc到flash的实战操作。通过硬件连接限制破解、emmc配置技巧、flash擦写策略优化等关键技术点,提供了可靠的远程更新解决方案,特别适合需要频繁更新boot.bin的应用场景。 阅读详情

Two Buildings

【分治】【决策单调性】
There are n buildings along a horizontal street. The buildings are next to each other along the street, and the i-th building from left to right has width 1 and height hi. Among the n buildings, we are to find two buildings, say the i-th building and j-th building with i<j, such that (hi+hj)∗(j−i) is maximized.

For example, the right figure shows 5 buildings, with heights 1, 3, 2, 5, 4, from left to right. If we choose the first 2 buildings, then we get (1+3)∗(2−1)=4. If we choose the first and fifth buildings, then we (1+4)∗(5−1)=20. The maximum value is achieved by the second and fifth buildings with heights 3 and 4, respectively: (3+4)∗(5−2)=21.

Write a program that, given a sequence of building heights, prints max1≤i<j≤n(hi+hj)∗(j−i).

Input
Your program is to read from standard input. The input starts with a line containing an integer n (2≤n≤1,000,000), where n is the number of buildings. The buildings are numbered 1 to n from left to right. The second line contains the heights of n buildings separated by a space such that the i-th number is the height hi of the i-th building (1≤hi≤1,000,000).

Output
Your program is to write to standard output. Print exactly one line. The line should contain max1≤i<j≤n(hi+hj)∗(j−i).

Examples

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;
}

Python计算时间差的方法 使用datetime模块是Python内置的方法,使用timedelta对象可以更精确地计算时间差,而使用dateutil库则提供了更为灵活和方便的操作方式。我们可以使用datetime模块中的datetime类来表示一个具体的日期和时间,并进行相应的运算。在Python中,我们经常需要计算日期和时间之间的差异,例如计算两个日期之间的天数、小时数、分钟数等。Python提供了多种方法来计算时间差,下面我们将介绍其中的几种常用方法,并附上相应的源代码。在上面的代码中,我们使用了dateutil库中的。 阅读详情

相关推荐

Reality Capture控制点修复/合并模型

通过增加控制点/修改对齐设置参数来修复模型被分为两个部分的解决方法

草履虫建模的博客 5253

L. Two Buildings(决策单调性 )详解

2020-2021 ACM-ICPC, Asia Seoul Regional Contest 补题 题目传送门 朴素算法(爆搜):o(n2n^2n2) 决策单调:o(n*log⁡2n\log_2^nlog2n​) 题意: 给一长度n(n<=1e6)的数组,hih_ihi​<=1e6,求max(hih_ihi​+hjh_jhj​)∗(j−i) 1≤i<j≤n. 思路: 直接求很难,进行公式变换 ( hjh_jhj​ - ( hih_ihi​ ) )∗(j−i) 1≤i<j

weixin_45819197的博客 924

MTK Sensor驱动调试实战:从AP到SCP的完整流程解析

本文详细解析了MTK平台Sensor驱动从AP侧到SCP侧的完整调试流程。内容涵盖AP侧驱动集成、DTS配置、内核编译与验证,以及SCP侧Tinysys框架下的代码集成、Overlay配置与I2C设置等核心步骤,并分享了中断唤醒、功耗优化及传感器数据校准等实战经验与常见问题排查方法,为硬件驱动工程师提供了一份全面的实战指南。

weixin_29175469的博客 354

Two Buildings(决策单调性+分治)

题意是求 max((a[j]+a[i])∗(j−i)),1≤i<j<nmax({(a[j] + a[i]) * (j - i)}), 1 \le i <j<nmax((a[j]+a[i])∗(j−i)),1≤i<j<n 可转化为求 max((a[j]−(−a[i]))∗(j−i))max({(a[j] - (-a[i])) * (j - i)})max((a[j]−(−a[i]))∗(j−i)) 令b[i]=−a[i]b[i] = - a[i]b[i]=−a[i] 即变.

weixin_43965698的博客 377

保姆级教程:不用看古早代码,5分钟搞懂泛微ecology9附件存储与接口调用

本文详细解析了泛微ecology9附件存储与接口调用的核心原理,提供从基础概念到实战操作的完整指南。通过拆解文档化附件设计理念、解析RESTful接口参数,并给出Python代码示例,帮助开发者快速掌握附件上传与业务集成的关键技巧,提升二次开发效率。

weixin_28688385的博客 351

逆向工具:一文讲述 Ghidra 的详细使用

Ghidra是由NSA开源的一款功能强大的逆向工程框架,支持多平台、多架构和多种文件格式分析。本文详细介绍了Ghidra的核心优势、安装配置方法、主界面功能模块,并通过一个CrackMe示例演示了完整的逆向分析流程。文章还讲解了高级功能如交叉引用、控制流图分析、数据类型重建和脚本自动化等,最后提供了常见文件格式的分析技巧。作为IDA Pro的免费替代方案,Ghidra适合个人学习、教学和中小项目使用。(149字)

数据知道的博客 4347

HDU4372 Count the Buildings (翻译+题解:斯特林数)

听教练讲题讲多了,不自觉就喜欢打比方了

DD(XYX)的硫氰化氘博客 451

基于STM32L4XX、HAL库的IP101GRI以太网收发器(PHY)驱动程序设计

define IP101GRI_PHY_ADDRESS 0x01 // 根据硬件设计设置PHY地址。#define IP101GRI_PHYSTS 0x10 // PHY状态寄存器。#define IP101GRI_PHYINIR 0x12 // PHY中断寄存器。#define IP101GRI_PHYCR 0x14 // PHY控制寄存器。#define IP101GRI_PHYID2 0x03 // PHY标识符2。

zhusl6688的博客 722

gym102920 L. Two Buildings(决策单调性+分治)

题意: 给定长度为n的数组h, 要求计算max{(h[i]+h[j])*(j-i)},其中i<j. 数据范围:n<=1e6,1<=h(i)<=1e6

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 884

[VT虚拟化驱动]安装DPC回调检测CPU对VT的支持

文章目录前言一、驱动基本框架二、安装DPC回调三、检测CPU对VT的支持本章代码def.h:DriverEntry.cpputil.cpp 前言 对于VT的介绍网上有很多详细的介绍,这里不再赘述,只需要知道它有比操作系统还高的权限,可以利用这一点进行某些操作,如内存隐藏, 无痕HOOK ,MSR HOOK, 调试或者反调试, 这里直奔主题 一、驱动基本框架 虚拟机设置里虚拟化引擎设置: 新建一个空的WDM工程,平台设置为x64平台,右键属性——>Inf2Cat——>Run Inf2Cat设置

吾无法无天的博客 3909

链接文件及功能安全:S32K3如何将FLASH驱动放到RAM里面、RAM如何实现软件复位数据不丢失操作。

在通过RTD的SDK也好MCAL也好,始终存在一个问题,生成的代码除了看门狗模块,默认都是放在flash里面,按照正常逻辑来看没啥大的问题,思考一个问题:Flash放在0x100的位置,但是此时我们要操作0x100怎么办?那肯定不允许啊,但是将flash的驱动放在RAM里面就可以避免这个问题的产生。Flash的特性:PF0能操作PF1,当然PF1也能操作PF0的,以此类推,只要不操作自身,想怎么玩都可以。这也是一个物理特性吧。

梦想技术家 2310

Blue F50 Cleats Damien Hirst Gets Two New Buildings From Designscape Architects

Damien Hirst Gets Two New Buildings From Designscape Architects Damien Hirst Blue F50 Cleats just added two new bu...

cisheng1429的博客 128

手把手教你学PCIE(1.38)--基本概念:ATU(地址转换单元)

ATU(Address Translation Unit)是一种硬件单元,用于在PCIe系统中进行地址转换。它将设备的本地地址(外部地址)转换为系统内存或配置空间中的全局地址(内部地址),反之亦然。ATU的工作原理:通过地址匹配和转换,确保事务能够在不同的地址空间之间正确路由。配置寄存器:通过配置寄存器来设置地址转换规则。应用场景:地址空间隔离、访问控制、动态地址管理、虚拟化和多租户。

MHD0815的博客 2057

GYM-102920-L. Two Buildings(决策单调性+分治)

题目链接 题目大意: 求一段序列的 (h[i]+h[j])*(j-i) 的最大值 step1: 转化一下题意 (h[i]+h[j])(j-i) = ( h[j] - (-h[i]) )(j-i) 令a[i] = -h[i] ,b[i] = h[i] 然后全部转化为两种坐标 (i,a[i]) (i,b[i]) 这样题目就转化成了在一个坐标系中 求最大矩形的面积(选出左上角和右下角的点) step2: 去除一些多余的点 对于一个固定的(i,a[i])坐标,要想矩形面积最大,肯定是越往左上越好 对于

wmy0536的博客 462

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1&sectionid=21.2.5 #include /* 题意:找闰年。 if((i%4==0 && i%100!=0) || i%400==0)count++; 3 2005 25 1855 12 2004 10000 2108 1904 43236 */ int ma

内方外圆 2521

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

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​)) 思路: 将式子转化为max((j−i)∗(cj−(−ci)))max((j-i)*(c_j-(-c_i)))max((j−i)∗(cj​−(−ci​))) 将(j,cj),(i,−ci)(j,c_j),(i,-c_i)(j,cj​),(i,−ci​)分别看做是矩形的左下角和右上角的点,问题就转化成了求矩形的最大面积。 假设a=(j

我们都有光明的未来 565

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》...

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=2 1.2.5 #include<stdio.h> /* 题意:找闰年。 if((i%4==0 && i%100!=0) || i%400==0)count++; 3 2005 25 1855...

weixin_30851409的博客 124

Twin Buildings

Twin Buildings 时间限制: 1 Sec 内存限制: 256 MB 题目描述 As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC Jakarta is planning to build two new buildings. These buildings should have a shape of a rectangle of the sa

Amber的博客 340

H - Twin Buildings ( 精度损失 )

H - Twin Buildings ( 精度损失 ) 题意: 有n个长方形的岛,给出长宽。现在想要在岛上建两个大小完全一样的长方形房子,房子的边必须和岛的边平行,问最大能建多么大的。 思路: 按照岛的最长边进行排序,前面的一定可以包括后面的,这样只需要考虑宽就好了。 注意: double存不下long long范围的值,会有精度损失。 处理方式看代码输出部分 Examples In...

石旭先森的博客 579

[找规律] 多校联合第二场 B题 Buildings

Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Your current task is

童凌的技术博客 789

Buildings II

As a traveling salesman in a globalized world, Alan has always moved a lot. He almost never lived in the same town for more than a few years until his heart yearned for a different place. However, th...

qq_43690454的博客 148

【Polya计数】Buildings II

Buildings II 题目描述 As a traveling salesman in a globalized world, Alan has always moved a lot. He almost never lived in the same town for more than a few years until his heart yearned for a...

weixin_30609287的博客 116

Buildings II Polya计数!

get 新知识:polya计数。先给出公式吧: ll ans=kuaisumi(c,n*n); ll res=0; for(i=1;i<=m;i++) { res=(res+kuaisumi(ans,gcd(i,m)))%mod; } ans代表c种颜色填n*n方格的方案数;res 代表填色的总方案数。gcd(i,m)代表旋转i次的循环节数。 问题 A: Buildings ...

weixin_43916298的博客 242

LeetCode每日一题(2222. Number of Ways to Select Buildings)

You are given a 0-indexed binary string s which represents the types of buildings along a street where: s[i] = ‘0’ denotes that the ith building is an office and s[i] = ‘1’ denotes that the ith building is a restaurant. As a city official, you would like t

wangjun861205的博客 271

Buildings Gym - 101873B

As a traveling salesman in a globalized world, Alan has always moved a lot. He almost never lived in the same town for more than a few years until his heart yearned for a different place. However, thi...

七九河开的博客 521
上一篇: 2021-02-01
下一篇: A - Initial Bet
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值