CodeForces-1159B-Expansion coefficient of the array
Let's call an array of non-negative integers a1,a2,…,an a k-extension for some non-negative integer k if for all possible pairs of indices 1≤i,j≤n the inequality k⋅|i−j|≤min(ai,aj) is satisfied. The expansion coefficient of the array a is the maximal integer k such that the array a is a k-extension. Any array is a 0-expansion, so the expansion coefficient always exists.
You are given an array of non-negative integers a1,a2,…,an. Find its expansion coefficient.
The first line contains one positive integer n — the number of elements in the array a (2≤n≤300000). The next line contains n non-negative integers a1,a2,…,an, separated by spaces (0≤ai≤10^9).
Print one non-negative integer — expansion coefficient of the array a1,a2,…,an.
input |
4 6 4 5 5 |
output |
1 |
input |
3 0 1 2 |
output |
0 |
input |
4 821 500 479 717 |
output |
239 |
In the first test, the expansion coefficient of the array [6,4,5,5] is equal to 1 because |i−j|≤min(ai,aj), because all elements of the array satisfy ai≥3. On the other hand, this array isn't a 2-extension, because 6=2⋅|1−4|≤min(a1,a4)=5 is false.
In the second test, the expansion coefficient of the array [0,1,2] is equal to 0 because this array is not a 1-extension, but it is 0-extension.
题解
对于数列 a1,a2,…,an,分析其中任意一项ai,考虑所有的aj >= ai(aj < ai的算在aj里面考虑了),则使得min(ai,aj) = ai,要使所有的j都满足k*|i-j| <= min(ai,aj) = ai,则对于ai来说,j应该尽量远离i,这样解出来的最大的k才是有用的(即对ai的k值的约束最紧)。显然最远的j应该是数列两端中的一端,但两端不一定大于ai。那怎么办呢?仔细一想,对于两端的情况,考虑最前端a1及最后端an:
- 如果a1 >= ai,则对于当前ai来说,k要满足k <= ai/|i-1|(如果i == 1,则说明k值没有限制)。如果a1 < ai,则对于当前ai来说,k要满足k <= a1/|i-1| < ai/|i-1|。
- 如果an >= ai,则对于当前ai来说,k要满足k <= ai/|i-n|(如果i == n,则说明k值没有限制)。如果an < ai,则对于当前ai来说,k要满足k <= an/|i-n| < ai/|i-n|。
- 在所有大于等于ai的aj中,k对于ai来说要满足k <= ai/|i-j|,而|i-j| <= |i-1|或|i-j| <= |i-n|,故ai/|i-1| <= ai/|i-j|或ai/|i-n| <= ai/|i-j|。
可见,对每项ai来说,考虑两端的项所解出来的k值必定有一项是有用的(即对ai的k值的约束最紧)。
枚举每一项求解出来的有用的k值,再取最小即得到最优答案。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <algorithm>
#define re register
#define il inline
#define ll long long
#define ld long double
const ll MAXN = 1e6+;
const ll INF = 1e9; //快读
il ll read()
{
char ch = getchar();
ll res = , f = ;
while(ch < '' || ch > '')
{
if(ch == '-') f = -;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
res = (res<<) + (res<<) + (ch-'');
ch = getchar();
}
return res*f;
} ll a[MAXN]; int main()
{
ll n = read();
for(re ll i = ; i <= n; ++i)
{
a[i] = read();
}
ll k = INF;
for(re ll i = ; i <= n; ++i)
{
k = std::min(i==?k:std::min(a[i],a[])/(i-),k);
k = std::min(i==n?k:std::min(a[i],a[n])/(n-i),k);
}
printf("%lld\n", k);
return ;
}
最新文章
- android 代码设置progressBar 颜色
- 安全性之DDOS的防护技巧
- windows-docker开发我常用命令 docker-machine ssh default
- Python核心编程--学习笔记--6--序列(下)列表、元组
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
- 51nod1495 中国好区间
- JSP学习笔记(一)
- 转ABAP将内表行列转换实例(动态内表) .
- JSF学习五Ajax
- 51单片机C语言学习笔记5:include的区别
- 让我的分页类获取sessionFactory
- [SDOI2010]粟粟的书架
- 每日冲刺报告——Day4(Java-Team)
- [转]当CPU飙高时,它在做什么
- C# -- 使用Ping检查网络是否正常
- COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问。最新解决方案
- 【原创】大叔经验分享(26)hive通过外部表读写elasticsearch数据
- Tomcat服务的安装及配置
- JDBC事务的处理-----模拟银行转账业务
- day05-表的三种关系
热门文章
- python中普通函数调用协程
- Kali Linux硬盘扩容
- mysql 数据库通过拷贝文件恢复方法
- 百度编辑器contentChange监听不到图片上传
- 网络分裂 redis 集群
- MYSQL Packet for query is too large (12054240 >; 4194304). You can change this value on the server by setting the max_allowed_packet&#39; variable.
- hyper-v启动虚拟机时提示“The application encountered an error while attempting to change the state of the machine ‘虚拟机名称&#39;”如何处理?
- C++提示没有与这些操作数匹配的<;<;运算符
- AI项目(CV方向)研发流程
- leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913)