当前位置:网站首页>【HDU】5248-序列变换(贪心+二分)「建议收藏」
【HDU】5248-序列变换(贪心+二分)「建议收藏」
2022-07-07 16:54:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
二分枚举长度改变的长度即可了
#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;
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116609.html原文链接:https://javaforall.cn
边栏推荐
- Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month
- “解密”华为机器视觉军团:华为向上,产业向前
- 3. About cookies
- IP netns command (memo)
- Embedded interview questions (algorithm part)
- Idea completely uninstalls installation and configuration notes
- 不能忽略的现货白银短线操作小技巧
- DeSci:去中心化科学是Web3.0的新趋势?
- Some key points in the analysis of spot Silver
- 清华、剑桥、UIC联合推出首个中文事实核查数据集:基于证据、涵盖医疗社会等多个领域
猜你喜欢

The live broadcast reservation channel is open! Unlock the secret of fast launching of audio and video applications

GSAP animation library

持续测试(CT)实战经验分享

Introduction de l'API commune de programmation de socket et mise en œuvre de socket, select, Poll et epoll

Wireshark analyzes packet capture data * cap

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

不能忽略的现货白银短线操作小技巧

嵌入式C语言程序调试和宏使用的技巧

Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month

Five network IO models
随机推荐
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
Charles+drony的APP抓包
Classification of regression tests
Continuous test (CT) practical experience sharing
Reuse of data validation framework Apache bval
Sports Federation: resume offline sports events in a safe and orderly manner, and strive to do everything possible for domestic events
[demo] circular queue and conditional lock realize the communication between goroutines
小试牛刀之NunJucks模板引擎
Creative changes brought about by the yuan universe
Download, installation and development environment construction of "harmonyos" deveco
Hash, bitmap and bloom filter for mass data De duplication
Usage of PHP interview questions foreach ($arr as $value) and foreach ($arr as $value)
Discuss | what preparations should be made before ar application is launched?
C语言中匿名的最高境界
What is the general yield of financial products in 2022?
将模型的记忆保存下来!Meta&UC Berkeley提出MeMViT,建模时间支持比现有模型长30倍,计算量仅增加4.5%...
学习open62541 --- [67] 添加自定义Enum并显示名字
抢占周杰伦
50亿,福建又诞生一只母基金
链式二叉树的基本操作(C语言实现)