当前位置:网站首页>[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
边栏推荐
- 3.关于cookie
- Continuous test (CT) practical experience sharing
- How many times is PTA 1101 B than a
- Antisamy: a solution against XSS attack tutorial
- Charles+Postern的APP抓包
- 初识缓存以及ehcache初体验「建议收藏」
- NAT地址转换
- Yunjing network technology interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- 线程池的拒绝策略
- 咋吃都不胖的朋友,Nature告诉你原因:是基因突变了
猜你喜欢

Basic operation of chain binary tree (implemented in C language)

虚拟数字人里的生意经

RISCV64

面试唯品会实习测试岗、抖音实习测试岗【真实投稿】
![[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

String type, constant type and container type of go language

Standard ACL and extended ACL

Reinforcement learning - learning notes 8 | Q-learning

SD_ DATA_ RECEIVE_ SHIFT_ REGISTER
![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]
随机推荐
数据验证框架 Apache BVal 再使用
[information security laws and regulations] review
How many times is PTA 1101 B than a
A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)
UVALive – 4621 Cav 贪心 + 分析「建议收藏」
Antisamy: a solution against XSS attack tutorial
unity2d的Rigidbody2D的MovePosition函数移动时人物或屏幕抖动问题解决
RISCV64
链式二叉树的基本操作(C语言实现)
The highest level of anonymity in C language
[C language] string function
Calculation of torque target value (ftorque) in servo torque control mode
2022-07-04 matlab reads video frames and saves them
PTA 1102 教超冠军卷
手把手教姐姐写消息队列
Datasimba launched wechat applet, and datanuza accepted the test of the whole scene| StartDT Hackathon
數據驗證框架 Apache BVal 再使用
咋吃都不胖的朋友,Nature告诉你原因:是基因突变了
Sports Federation: resume offline sports events in a safe and orderly manner, and strive to do everything possible for domestic events
单臂路由和三层交换的简单配置