当前位置:网站首页>【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
边栏推荐
- Disk storage chain B-tree and b+ tree
- 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
- 单臂路由和三层交换的简单配置
- 清华、剑桥、UIC联合推出首个中文事实核查数据集:基于证据、涵盖医疗社会等多个领域
- 嵌入式面试题(算法部分)
- 如何给“不卖笔”的晨光估值?
- Wireshark分析抓包数据*.cap
- 【软件测试】从企业版BOSS直聘,看求职简历,你没被面上是有原因的
- Complete e-commerce system
- Introduction of common API for socket programming and code implementation of socket, select, poll, epoll high concurrency server model
猜你喜欢
Redis cluster and expansion
如何给“不卖笔”的晨光估值?
Cadre de validation des données Apache bval réutilisé
微信网页调试8.0.19换掉X5内核,改用xweb,所以x5调试方式已经不能用了,现在有了解决方案
Summary of evaluation indicators and important knowledge points of regression problems
AntiSamy:防 XSS 攻击的一种解决方案使用教程
CVPR 2022 - learning non target knowledge for semantic segmentation of small samples
【C语言】字符串函数
Creative changes brought about by the yuan universe
C语言中匿名的最高境界
随机推荐
Calculation of torque target value (ftorque) in servo torque control mode
嵌入式C语言程序调试和宏使用的技巧
CVPR 2022 - learning non target knowledge for semantic segmentation of small samples
Learn to make dynamic line chart in 3 minutes!
【塔望方法论】塔望3W消费战略 - U&A研究法
数据验证框架 Apache BVal 再使用
I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
RISCV64
3.关于cookie
将模型的记忆保存下来!Meta&UC Berkeley提出MeMViT,建模时间支持比现有模型长30倍,计算量仅增加4.5%...
Redis的发布与订阅
Download, installation and development environment construction of "harmonyos" deveco
链式二叉树的基本操作(C语言实现)
A few simple steps to teach you how to see the K-line diagram
PTA 1102 教超冠军卷
云景网络科技面试题【杭州多测师】【杭州多测师_王sir】
Realize payment function in applet
线程池的拒绝策略
我感觉被骗了,微信内测 “大小号” 功能,同一手机号可注册两个微信
The highest level of anonymity in C language