当前位置:网站首页>D2. Chopping Carrots (Hard Version) (每日一题)
D2. Chopping Carrots (Hard Version) (每日一题)
2022-07-25 14:21:00 【追随远方的某R】
D2. Chopping Carrots (Hard Version)
题意:给定一个长度为n的数组a,要你拟定一个长度为n的数组p,使得下列公式求得的值最小

做法:固定最小值,考虑枚举使得最大值最小化,利用整除分块的思想,ai/pi的整除值实际上只有sqrt(ai)个,n*sqrt(n)的复杂度可以接受。
我们设max[i]数组,其意义为:a[i]/p[i]最小值为i时的最大值为多少(考虑多个ai的情况就能明白了),对于每个a[i]都要枚举。
假如现在的这个区间是[]
对于代码中maxx数组的更新,模拟一下便于理解
比如基值是100 第一段区间是(51,100],那么最小值是51的情况下我至少得是100
下面是代码的模拟。
比如此时ai是100
第一次temp=100
r=1
maxx[100+1]=无穷大
pv=100
第二次
temp=50
r=2
maxx[50+1]=max(maxx[50+1],100)
第三次
temp=33
r=3
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 100100;
int t,n,k,a[MAXN],maxx[MAXN];
int main()
{
for(cin>>t;t;t--)
{
cin>>n>>k;
memset(maxx,0,sizeof(maxx));
for(int i=0;i<n;i++)
{
cin>>a[i];
int pv=1e9;
for(int j=1,r,temp;j<=min(a[i],k);j=r+1)
{
temp=a[i]/j;
r=a[i]/temp;//整除分块的思想
maxx[temp+1]=max(maxx[temp+1],pv);//由于整除分块是的值是递减的,所以上一个值一定比现在的大
pv=temp;
}
maxx[0]=max(maxx[0],pv);
}
int ans=1e9;
int cm=0;
for(int i=0;i<=a[0];i++)
{
cm=max(cm,maxx[i]);
ans=min(ans,cm-i);
}
cout<<ans<<"\n";
}
return 0;
}
边栏推荐
- The main function of component procurement system, digital procurement helps component enterprises develop rapidly
- From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part 2)
- 机械制造业数字化新“引擎”供应链协同管理系统助力企业精细化管理迈上新台阶
- Throwing OutOfMemoryError “Could not allocate JNI Env“
- CSV文本文件导入excel的四种方法
- ~4.2 CCF 2021-12-1 sequence query
- Apple failed to synchronize on its mobile terminal, so it exited the login. As a result, it could not log in again
- Resource not found: rgbd_launch 解决方案
- What you must know about data engineering in mlops
- CDA level Ⅰ 2021 new version simulation question 1 (with answers)
猜你喜欢

Under the epidemic, the biomedical industry may usher in breakthrough development

Why do China Construction and China Railway need this certificate? What is the reason?

The practice of depth estimation self-monitoring model monodepth2 in its own data set -- single card / multi card training, reasoning, onnx transformation and quantitative index evaluation

Melodic + Realsense D435i 配置及错误问题解决

Realize a family security and environmental monitoring system (II)

Emergency science | put away this summer safety guide and let children spend the summer vacation safely!

sqli-labs Basic Challenges Less1-10

~4.1 sword finger offer 05. replace spaces
知名手写笔记软件 招 CTO·坐标深圳

Interpretation of featdepth self-monitoring model for monocular depth estimation (Part 2) -- use of openmmlab framework
随机推荐
如何设计一个高并发系统?
Realize a family security and environmental monitoring system (I)
【cartographer_ros】八: 官方Demo参数配置和效果
Gartner 2022 top technology trend: Super automation
用GaussDB(for Redis)存画像,推荐业务轻松降本60%
~5 new solution of CCF 2021-12-2 sequence query
Gateway 网关报错 SERVICE_UNAVAILABLE
Filters get the data in data; Filters use data in data
网络安全应急响应技术实战指南(奇安信)
DVWA practice - brute force cracking
Reverse Integer
应用实践:Paddle分类模型大集成者[PaddleHub、Finetune、prompt]
依迅总经理孙峰:公司已完成股改,准备IPO
基于PaddleOCR开发uni-app离线身份证识别插件
【口才】谈判说服技巧及策略
Opencv video tracking "suggestions collection"
~4.1 sword finger offer 05. replace spaces
安防市场进入万亿时代,安防B2B网上商城平台精准对接深化企业发展路径
PS制作加载GIF图片教程
Hyperautomation for the enhancement of automation in industries