当前位置:网站首页>[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
边栏推荐
- Industry case | digital operation base helps the transformation of life insurance industry
- 高温火烧浑不怕,钟薛高想留清白在人间
- Multimodal point cloud fusion and visual location based on image and laser
- LeetCode 890(C#)
- 數據驗證框架 Apache BVal 再使用
- 企业MES制造执行系统的分类与应用
- RISCV64
- Thread pool and singleton mode and file operation
- 线程池中的线程工厂
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
猜你喜欢
抢占周杰伦
Antisamy: a solution against XSS attack tutorial
直播预约通道开启!解锁音视频应用快速上线的秘诀
Kirk borne's selection of learning resources this week [click the title to download directly]
Static routing configuration
RISCV64
GSAP animation library
A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)
Idea completely uninstalls installation and configuration notes
企业展厅设计中常用的三种多媒体技术形式
随机推荐
Interview vipshop internship testing post, Tiktok internship testing post [true submission]
Thread pool and singleton mode and file operation
Kirk borne's selection of learning resources this week [click the title to download directly]
NAT地址转换
How to choose the appropriate automated testing tools?
gsap动画库
完整的电商系统
Cloud security daily 220707: Cisco Expressway series and telepresence video communication server have found remote attack vulnerabilities and need to be upgraded as soon as possible
3.关于cookie
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
标准ACL与扩展ACL
Reinforcement learning - learning notes 8 | Q-learning
伺服力矩控制模式下的力矩目标值(fTorque)计算
Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month
How many times is PTA 1101 B than a
Tsinghua, Cambridge and UIC jointly launched the first Chinese fact verification data set: evidence-based, covering many fields such as medical society
SQLite SQL exception near "with": syntax error
【软件测试】从企业版BOSS直聘,看求职简历,你没被面上是有原因的
"Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
高考填志愿规则