当前位置:网站首页>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;
}
边栏推荐
- Polymorphism and interface
- Introduction to PHP
- 飞沃科技IPO过会:年营收11.3亿 湖南文旅与沅澧投资是股东
- It is predicted that 2021 will accelerate the achievement of super automation beyond RPA
- Flask SSTI injection learning
- Throwing OutOfMemoryError “Could not allocate JNI Env“
- Basic theory of monocular depth estimation and paper learning summary
- Goldfish rhca memoirs: cl210 management storage -- object storage
- Structure size
- Keys and scan based on redis delete keys with TTL -1
猜你喜欢

阿里云安装MYSQL5.7

基于redis的keys、scan删除ttl为-1的key

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

Teach you how to apply for SSL certificate

Data analysis business core

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)

Resource not found: rgbd_launch 解决方案

~4.2 CCF 2021-12-1 sequence query

依迅总经理孙峰:公司已完成股改,准备IPO

It is predicted that 2021 will accelerate the achievement of super automation beyond RPA
随机推荐
Realsense-Ros安装配置介绍与问题解决
如何让一套代码完美适配各种屏幕?
CDA level Ⅰ 2021 new version simulation question 1 (with answers)
DVWA practice - brute force cracking
Huawei ENSP router static route (the next hop address of the default route)
Mlops column introduction
安防市场进入万亿时代,安防B2B网上商城平台精准对接深化企业发展路径
MySQL table operation
Reverse Integer
Introduction to PHP
Doris learning notes integration with other systems
Gateway 网关报错 SERVICE_UNAVAILABLE
Wangeditor rich text editor
苹果手机端同步不成功,退出登录,结果再也登录不了了
Why do China Construction and China Railway need this certificate? What is the reason?
The supply chain collaborative management system, a new "engine" of digitalization in machinery manufacturing industry, helps enterprises' refined management to a new level
idea正则表达式替换(idea正则搜索)
Basic theory of monocular depth estimation and paper learning summary
Thymeleaf controls whether display is displayed through style
Summary of some problems about left value and right value [easy to understand]