当前位置:网站首页>[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
边栏推荐
- Will low code help enterprises' digital transformation make programmers unemployed?
- Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
- Redis
- 标准ACL与扩展ACL
- 国内的软件测试会受到偏见吗
- [unity shader] insert pass to realize the X-ray perspective effect of model occlusion
- 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
- 50亿,福建又诞生一只母基金
- 【MIME笔记】
- Kirk Borne的本周学习资源精选【点击标题直接下载】
猜你喜欢
随机推荐
如何选择合适的自动化测试工具?
Big Ben (Lua)
Nat address translation
Redis publishing and subscription
LeetCode 890(C#)
2022上半年朋友圈都在传的10本书,找到了
【Base64笔记】「建议收藏」
国内首次!这家中国企业的语言AI实力被公认全球No.2!仅次于谷歌
3. About cookies
Reject policy of thread pool
将模型的记忆保存下来!Meta&UC Berkeley提出MeMViT,建模时间支持比现有模型长30倍,计算量仅增加4.5%...
Charles+drony的APP抓包
Do you know all four common cache modes?
【剑指 Offer】59 - I. 滑动窗口的最大值
Flipping Game(枚举)
Rules for filling in volunteers for college entrance examination
coming! Gaussdb (for Cassandra) new features appear
Kirk Borne的本周学习资源精选【点击标题直接下载】
Datasimba launched wechat applet, and datanuza accepted the test of the whole scene| StartDT Hackathon
【塔望方法论】塔望3W消费战略 - U&A研究法