当前位置:网站首页>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;
}
边栏推荐
- Word set paste to retain only text
- 2271. 毯子覆盖的最多白色砖块数 ●●
- Detailed explanation of how R language converts large Excel files into DTA format
- 苹果手机端同步不成功,退出登录,结果再也登录不了了
- Leetcode 205. isomorphic string (2022.07.24)
- Depth estimation self-monitoring model monodepth2 paper summary and source code analysis [theoretical part]
- Easy entry natural language processing series 12 hidden Markov models
- Nuc980 set up SSH xshell connection
- Typora cannot open the prompt to install a new version solution
- 金鱼哥RHCA回忆录:CL210管理存储--对象存储
猜你喜欢

Filters get the data in data; Filters use data in data

sqli-labs Basic Challenges Less11-22

How to make a set of code fit all kinds of screens perfectly?

maya建模练习

Digital Twins - cognition

如何设计一个高并发系统?

sqli-labs Basic Challenges Less1-10

Realize a family security and environmental monitoring system (I)

IDEA报错 Failed to determine a suitable driver class

Cologne new energy IPO was terminated: the advanced manufacturing and Zhanxin fund to be raised is the shareholder
随机推荐
51单片机学习笔记(1)
Data analysis business core
thymeleaf设置disabled
Comprehensive sorting and summary of maskrcnn code structure process of target detection and segmentation
苹果手机端同步不成功,退出登录,结果再也登录不了
NUC980 设置SSH Xshell连接
Realize a family security and environmental monitoring system (I)
Sqli labs installation environment: ubuntu18 php7
Vs2017 large factory ERP management system source code factory general ERP source code
opencv视频跟踪「建议收藏」
飞沃科技IPO过会:年营收11.3亿 湖南文旅与沅澧投资是股东
Mlops column introduction
Pytorch uses tensorboard to realize visual summary
[original] nine point calibration tool for robot head camera calibration
[directory blasting tool] information collection stage: robots.txt, Yujian, dirsearch, dirb, gobuster
Okaleido ecological core equity Oka, all in fusion mining mode
Mongodb源码部署以及配置
Matplotlib data visualization three minutes entry, half an hour enchanted?
MySQL table operation
依迅总经理孙峰:公司已完成股改,准备IPO