当前位置:网站首页>[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
边栏推荐
- 完整的电商系统
- gsap动画库
- ES6 note 1
- Big Ben (Lua)
- Reject policy of thread pool
- App capture of charles+postern
- UVALive – 4621 Cav 贪心 + 分析「建议收藏」
- [information security laws and regulations] review
- I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
- The live broadcast reservation channel is open! Unlock the secret of fast launching of audio and video applications
猜你喜欢
10 schemes to ensure interface data security
完整的电商系统
Do you know all four common cache modes?
CVPR 2022丨学习用于小样本语义分割的非目标知识
String type, constant type and container type of go language
Desci: is decentralized science the new trend of Web3.0?
行业案例|数字化经营底座助力寿险行业转型
Cadre de validation des données Apache bval réutilisé
Nunjuks template engine
[unity shader] insert pass to realize the X-ray perspective effect of model occlusion
随机推荐
Standard ACL and extended ACL
Charles+Postern的APP抓包
Nunjuks template engine
The top of slashdata developer tool is up to you!!!
初识缓存以及ehcache初体验「建议收藏」
DeSci:去中心化科学是Web3.0的新趋势?
国内首次!这家中国企业的语言AI实力被公认全球No.2!仅次于谷歌
二叉树的基本概念和性质
Wireshark analyzes packet capture data * cap
虚拟数字人里的生意经
unity2d的Rigidbody2D的MovePosition函数移动时人物或屏幕抖动问题解决
A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)
RIP和OSPF的区别和配置命令
Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month
直播预约通道开启!解锁音视频应用快速上线的秘诀
ES6 note 1
"Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
Charles+drony的APP抓包
Reject policy of thread pool
Rules for filling in volunteers for college entrance examination