当前位置:网站首页>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;
}
边栏推荐
- 苹果手机端同步不成功,退出登录,结果再也登录不了
- Summary of some problems about left value and right value [easy to understand]
- Easy entry natural language processing series 12 hidden Markov models
- bond0脚本
- Introduction to PHP
- Pytorch training code writing skills, dataloader, Einstein logo
- 如何让一套代码完美适配各种屏幕?
- 为什么中建、中铁都需要这本证书?究竟是什么原因?
- 数字孪生 - 认知篇
- 机械制造业数字化新“引擎”供应链协同管理系统助力企业精细化管理迈上新台阶
猜你喜欢

Mongodb源码部署以及配置

基于浏览器的分屏阅读

苹果官网产品打折 买iPhone 13 Pro Max 可省600元

Okaleido生态核心权益OKA,尽在聚变Mining模式

关于ROS2安装connext RMW的进度条卡在13%问题的解决办法

Hyperautomation for the enhancement of automation in industries

科隆新能源IPO被终止:拟募资6亿 先进制造与战新基金是股东

Doris学习笔记之与其他系统集成

Interpretation of featdepth self-monitoring model for monocular depth estimation (Part I) -- paper understanding and core source code analysis

Mysql表的操作
随机推荐
From Anaconda to tensorflow to jupyter, step on the pit and fill it all the way
Detailed explanation of Telnet remote login AAA mode [Huawei ENSP]
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 I)
机械制造业数字化新“引擎”供应链协同管理系统助力企业精细化管理迈上新台阶
Keys and scan based on redis delete keys with TTL -1
Four methods of importing CSV text files into Excel
Day1: 130 questions in three languages
2271. 毯子覆盖的最多白色砖块数 ●●
华为ensp路由器静态路由(默认路由的下一跳地址)
PS making and loading GIF pictures tutorial
金鱼哥RHCA回忆录:CL210管理存储--对象存储
Why do China Construction and China Railway need this certificate? What is the reason?
opencv视频跟踪「建议收藏」
sqli-labs Basic Challenges Less1-10
RuntimeError: CUDA out of memory(已解决)[通俗易懂]
苹果官网产品打折 买iPhone 13 Pro Max 可省600元
苹果手机端同步不成功,退出登录,结果再也登录不了了
Maya modeling exercise
手把手教你申请SSL证书
AI model risk assessment Part 1: motivation