当前位置:网站首页>[HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
[HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
2022-07-07 19:09:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
The length of binary enumeration can be changed
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF = 3000000;
const int maxn = 100005;
int n,arr[maxn],arr2[maxn];
bool solve(int x){
memcpy(arr2,arr,sizeof(arr));
for(int i = 1; i <= n; i++){
if(arr2[i] > arr2[i - 1]){
arr2[i] = max(arr2[i - 1] + 1,arr2[i] - x);
}
else{
if(arr2[i] + x <= arr2[i - 1]) return false;
arr2[i] = arr2[i - 1] + 1;
}
}
return true;
}
int main(){
int T,Case = 1;
scanf("%d",&T);
arr[0] = -INF;
while(T--){
scanf("%d",&n);
for(int i = 1; i <= n; i++)
scanf("%d",&arr[i]);
int l = 0,r = INF;
int ans = n;
while(l <= r){
int mid = (l + r) >> 1;
if(solve(mid)){
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
printf("Case #%d:\n",Case++);
printf("%d\n",ans);
}
return 0;
}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116609.html Link to the original text :https://javaforall.cn
边栏推荐
- 【塔望方法论】塔望3W消费战略 - U&A研究法
- Usage of PHP interview questions foreach ($arr as $value) and foreach ($arr as $value)
- 企业MES制造执行系统的分类与应用
- Complete e-commerce system
- ip netns 命令(备忘)
- 6. About JWT
- Five network IO models
- RIP和OSPF的区别和配置命令
- 鸿蒙智能家居【1.0】
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
猜你喜欢
高温火烧浑不怕,钟薛高想留清白在人间
3. About cookies
[paper sharing] where's crypto?
[software test] from the direct employment of the boss of the enterprise version, looking at the resume, there is a reason why you are not covered
[tpm2.0 principle and Application guide] Chapter 16, 17 and 18
SlashData开发者工具榜首等你而定!!!
Redis cluster and expansion
The top of slashdata developer tool is up to you!!!
直播预约通道开启!解锁音视频应用快速上线的秘诀
The highest level of anonymity in C language
随机推荐
Hutool - lightweight DB operation solution
Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month
脑洞从何而来?加州大学最新研究:有创造力的人神经连接会「抄近道」
DeSci:去中心化科学是Web3.0的新趋势?
Flipping Game(枚举)
【Unity Shader】插入Pass实现模型遮挡X光透视效果
How to implement safety practice in software development stage
国内首次!这家中国企业的语言AI实力被公认全球No.2!仅次于谷歌
[Tawang methodology] Tawang 3W consumption strategy - U & a research method
Basic concepts and properties of binary tree
10 schemes to ensure interface data security
Micro service remote debug, nocalhost + rainbow micro service development second bullet
[unity shader] insert pass to realize the X-ray perspective effect of model occlusion
Skills of embedded C language program debugging and macro use
Redis
Interview vipshop internship testing post, Tiktok internship testing post [true submission]
Three forms of multimedia technology commonly used in enterprise exhibition hall design
Nunjuks template engine
The performance and efficiency of the model that can do three segmentation tasks at the same time is better than maskformer! Meta & UIUC proposes a general segmentation model with better performance t
Datasimba launched wechat applet, and datanuza accepted the test of the whole scene| StartDT Hackathon