当前位置:网站首页>D2. picking carrots (hard version) (one question per day)
D2. picking carrots (hard version) (one question per day)
2022-07-25 14:27:00 【Follow some R in the distance】
D2. Chopping Carrots (Hard Version)
The question : Given a length of n Array of a, I want you to draw up a length of n Array of p, Minimize the value obtained by the following formula 

practice : Fixed minimum , Consider enumerations to minimize the maximum , Using the idea of dividing into blocks ,ai/pi The integer division value of is actually only sqrt(ai) individual ,n*sqrt(n) The complexity is acceptable .
We set up max[i] Array , Its significance is :a[i]/p[i] The minimum value is i What is the maximum value of ( Consider multiple ai You can understand the situation ), For each a[i] All have to enumerate .
Suppose the current interval is []
For code maxx Array update , Simulate it for understanding
For example, the base value is 100 The first interval is (51,100], Then the minimum value is 51 In this case, I have to at least 100
The following is the code simulation .
For example, at this time ai yes 100
for the first time temp=100
r=1
maxx[100+1]= infinity
pv=100
The second time
temp=50
r=2
maxx[50+1]=max(maxx[50+1],100)
third time
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;// The idea of dividing into blocks
maxx[temp+1]=max(maxx[temp+1],pv);// Because the value of dividing blocks is decreasing , So the previous value must be larger than the current one
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;
}
边栏推荐
- Realize a family security and environmental monitoring system (I)
- Matplotlib data visualization three minutes entry, half an hour enchanted?
- Deep understanding of pytorch distributed parallel processing tool DDP -- starting from bugs in engineering practice
- sqli-labs Basic Challenges Less1-10
- 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)
- BIO、NIO、AIO示例
- From Anaconda to tensorflow to jupyter, step on the pit and fill it all the way
- 如何让一套代码完美适配各种屏幕?
- Realize a family security and environmental monitoring system (II)
- Problems and extensions of the monocular depth estimation model featdepth in practice
猜你喜欢

Gartner 2022 top technology trend: Super automation

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)

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

手把手教你申请SSL证书

A small part is exposed on one or both sides of the swiper

为什么中建、中铁都需要这本证书?究竟是什么原因?
![Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]](/img/b6/62a346174bfa63fe352f9ef7596bfc.png)
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]

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)

Mysql表的操作

Matplotlib data visualization three minutes entry, half an hour enchanted?
随机推荐
Products on Apple's official website can save 600 yuan by buying iPhone 13 Pro max at a discount
PS制作加载GIF图片教程
知名手写笔记软件 招 CTO·坐标深圳
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]
filters获取data中的数据;filters使用data中的数据
【口才】谈判说服技巧及策略
Maya modeling exercise
Problems and extensions of the monocular depth estimation model featdepth in practice
Throwing OutOfMemoryError “Could not allocate JNI Env“
PT100 temperature measurement circuit diagram (AD590 typical temperature measurement circuit)
Goldfish rhca memoirs: cl210 managing storage -- managing shared file systems
Huawei ENSP router static route (the next hop address of the default route)
C language and SQL Server database technology
idea正则表达式替换(idea正则搜索)
如何让一套代码完美适配各种屏幕?
苹果官网产品打折 买iPhone 13 Pro Max 可省600元
Apple failed to synchronize on its mobile terminal, and logged out. As a result, it could not log in again
OverTheWire-Bandit
DVWA practice - brute force cracking
Sqli labs installation environment: ubuntu18 php7