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 ;
}
CodeForces-1159B-Expansion coefficient of the array的更多相关文章
- Codeforces 221d D. Little Elephant and Array
二次联通门 : Codeforces 221d D. Little Elephant and Array /* Codeforces 221d D. Little Elephant and Array ...
- Codeforces Round #181 (Div. 2) A. Array 构造
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...
- Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配
题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...
- Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】
传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...
- codeforces 558B. Amr and The Large Array 解题报告
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...
- CodeForces Round #179 (295A) - Greg and Array
题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include < ...
- Codeforces 1105C: Ayoub and Lost Array(递推)
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...
- Codeforces 1114F Please, another Queries on Array? [线段树,欧拉函数]
Codeforces 洛谷:咕咕咕 CF少有的大数据结构题. 思路 考虑一些欧拉函数的性质: \[ \varphi(p)=p-1\\ \varphi(p^k)=p^{k-1}\times (p-1)= ...
- Codeforces 1114F Please, another Queries on Array? 线段树
Please, another Queries on Array? 利用欧拉函数的计算方法, 用线段树搞一搞就好啦. #include<bits/stdc++.h> #define LL ...
随机推荐
- centos7--zabbix3.4微信报警
1.申请企业微信 1.1 注册企业微信的地址 https://qy.weixin.qq.com/ 1.2 按照提示进行填写 1.3 完善个人信息: 1.4 创建应用 根据提示创建应用: 1.5 筛出重 ...
- Win10 剪贴板 快捷键是什么?
使用基于云的剪贴板从一台电脑上复制图像和文本并粘贴到另一台电脑上.你不仅可以从剪贴板历史记录中粘贴,还可以固定你发现自己经常使用的项目. 若要随时访问剪贴板历史记录,请按 Windows 徽标键 ...
- GIS空间分析案例_图层逐要素导出地理处理工具
GIS空间分析案例_图层逐要素导出地理处理工具 商务合作,科技咨询,版权转让:向日葵,135-4855__4328,xiexiaokui#qq.com 目的:导出图层的每个要素 使用方法:指定输入图层 ...
- Vuejs函数式组件,你值得拥有(1)
函数式组件在React社区很流行使用,那么在vue里面我们要怎么用呢 下面会涉及到的知识点: 高阶函数.状态.实例.vue组件 什么是函数式组件 我们可以把函数式组件想像成组件里的一个函数,入参是渲染 ...
- SQLServer 拼接列
想把表里modified_by和source这两列拼接成一行
- Flutter 中AlertDialog确认提示弹窗
import 'package:flutter/material.dart'; import 'dart:async'; enum Action { Ok, Cancel } class AlertD ...
- 一个Redis实例适合存储不同应用程序的数据吗?
Redis支持多个数据库,并且每个数据库的数据是隔离的不能共享,并且基于单机才有,如果是集群就没有数据库的概念. Redis是一个字典结构的存储服务器,而实际上一个Redis实例提供了多个用来存储数据 ...
- linux非root用户安装ncurses-devel依赖
很明显,如果我们通过yum或rpm下载安装,始终无法绕开root用户,除非我们不用yum或rpm.嗯,我们直接用源码安装.下载源码包,到http://ftp.gnu.org/gnu/ncurses/我 ...
- Django Timezone 处理
https://blog.csdn.net/qq_37049781/article/details/79347278 Django 中的时区在现实环境中,存在有多个时区.用户之间很有可能存在于不同的时 ...
- idea的一些常用快捷键
快捷键 1.进入实现方法的快捷键 Ctrl + Alt + B Ctrl + Alt + 鼠标点击 2.自动给方法添加注释的快捷键 输入/**,然后回车 3.删除一行 CTRL + Y / CTRL ...