当前位置:网站首页>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;
}
边栏推荐
- Okaleido ecological core equity Oka, all in fusion mining mode
- Matplotlib data visualization three minutes entry, half an hour enchanted?
- 金鱼哥RHCA回忆录:CL210管理存储--对象存储
- Apple failed to synchronize on its mobile terminal, so it exited the login. As a result, it could not log in again
- Thymeleaf setting disabled
- CDA level1 double disk summary
- [eloquence] negotiation persuasion skills and Strategies
- 快速搭建Dobbo小Demo
- 网络安全应急响应技术实战指南(奇安信)
- 软件测试 -- 1 软件测试知识大纲梳理
猜你喜欢

Realize a family security and environmental monitoring system (I)

English语法_不定代词 - other / another

sudo rosdep init Error ROS安装问题解决方案
![Depth estimation self-monitoring model monodepth2 paper summary and source code analysis [theoretical part]](/img/22/17250eabf067b5b1b9b71e6e0ff14e.png)
Depth estimation self-monitoring model monodepth2 paper summary and source code analysis [theoretical part]

Doris learning notes integration with other systems

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

IDEA设置提交SVN时忽略文件配置

~4.2 CCF 2021-12-1 sequence query

The supply chain collaborative management system, a new "engine" of digitalization in machinery manufacturing industry, helps enterprises' refined management to a new level

How to design a high concurrency system?
随机推荐
thymeleaf通过样式控制display是否显示
MySQL table operation
实现一个家庭安防与环境监测系统(二)
bond0脚本
基于redis的keys、scan删除ttl为-1的key
[cartographer_ros] VIII: Official demo parameter configuration and effect
Filters get the data in data; Filters use data in data
RuntimeError: CUDA out of memory(已解决)[通俗易懂]
Melodic + Realsense D435i 配置及错误问题解决
AI model risk assessment Part 1: motivation
Can the variable name be in Chinese? Directly fooled people
VS2017大型工厂ERP管理系统源码 工厂通用ERP源码
机械制造业数字化新“引擎”供应链协同管理系统助力企业精细化管理迈上新台阶
Polymorphism and interface
Huawei ENSP router static route (the next hop address of the default route)
pytorch训练代码编写技巧、DataLoader、爱因斯坦标示
A small part is exposed on one or both sides of the swiper
Teach you how to apply for SSL certificate
From Anaconda to tensorflow to jupyter, step on the pit and fill it all the way
元器件采购系统的主要功能,数字化采购助力元器件企业飞速发展