当前位置:网站首页>[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
边栏推荐
- Basic concepts and properties of binary tree
- Redis的发布与订阅
- [sword finger offer] 59 - I. maximum value of sliding window
- Static routing configuration
- How many times is PTA 1101 B than a
- Five network IO models
- CVPR 2022 - learning non target knowledge for semantic segmentation of small samples
- cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)
- 手把手教姐姐写消息队列
- Continuous test (CT) practical experience sharing
猜你喜欢

标准ACL与扩展ACL

行业案例|数字化经营底座助力寿险行业转型
![[Blue Bridge Cup training 100 questions] sort scratch from small to large. Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question](/img/08/5f4b4e2700606554516807c01454fd.png)
[Blue Bridge Cup training 100 questions] sort scratch from small to large. Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question

高温火烧浑不怕,钟薛高想留清白在人间
![Interview vipshop internship testing post, Tiktok internship testing post [true submission]](/img/69/b27255c303150430df467ff3b5cd08.gif)
Interview vipshop internship testing post, Tiktok internship testing post [true submission]

Idea completely uninstalls installation and configuration notes
![[unity shader] insert pass to realize the X-ray perspective effect of model occlusion](/img/86/251404b81ae4ab6dbfd9da73cd11cb.png)
[unity shader] insert pass to realize the X-ray perspective effect of model occlusion

二叉树的基本概念和性质

In 2021, the national average salary was released. Have you reached the standard?

6.关于jwt
随机推荐
3. About cookies
DeSci:去中心化科学是Web3.0的新趋势?
2022.07.02
【MIME笔记】
单臂路由和三层交换的简单配置
抢占周杰伦
Rules for filling in volunteers for college entrance examination
Basic concepts and properties of binary tree
[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
The highest level of anonymity in C language
企业MES制造执行系统的分类与应用
6.关于jwt
完整的电商系统
数据验证框架 Apache BVal 再使用
Golang client server login
Industry case | digital operation base helps the transformation of life insurance industry
链式二叉树的基本操作(C语言实现)
企业展厅设计中常用的三种多媒体技术形式
[unity shader] insert pass to realize the X-ray perspective effect of model occlusion
Thread pool and singleton mode and file operation