百度之星初赛(1) 1003 序列变换 二分搜索
来源:互联网 发布:实时数据监控 编辑:程序博客网 时间:2024/05/16 15:26
#include <cstdio>#include <iostream>#include <cstring>#include <set>#include <cmath>#include <algorithm>#include <vector>#include <map>using namespace std;int n;int a[100015];int b[100015];int fun(int m){ for(int i = 0;i < n;i++){ if(i == 0){ b[i] = a[i]-m; } else{ if(a[i]+m < b[i-1]+1){ return 0; } else{ if(a[i]-m < b[i-1]+1){ b[i] = b[i-1] + 1; } else { b[i] = a[i] - m; } } } } return 1;}int main(){ int t; cin >> t; for(int kcase = 1; kcase <= t;kcase ++){ scanf("%d",&n); int maxn = 0; for(int i = 0;i < n;i++){ scanf("%d",&a[i]); if(a[i] > maxn){ maxn = a[i]; } } int l = 0; int r = 1000000+1; memset(b,0,sizeof(b)); while(l < r){ int m = l + (r-l)/2; if(fun(m)){ r = m; } else{ l = m + 1; } } printf("Case #%d:\n",kcase); printf("%d\n",l); } return 0;}
0 0
- 百度之星初赛(1) 1003 序列变换 二分搜索
- 百度之星2015初赛(1)1003 HDOJ5248 序列变换(二分 贪心)
- 【百度之星初赛】序列变换(二分,贪心)
- 百度之星 2015 初赛(1) 1003 序列变换
- BC 2015年百度之星程序设计大赛 - 初赛(1)(序列变换-二分答案贪心)
- 2015年百度之星初赛(1) --- C 序列变换
- 序列变换 2015百度之星(初赛)1005
- [二分+贪心]2015百度之星初赛第一场 序列变换
- 百度之星初赛1002(二分搜索)
- 2015百度之星初赛1 1003(二分)
- 百度之星 2015 初赛(2) 1005 序列变换
- 【百度之星初赛2】序列变换(最长上升子序列)
- 2015百度之星初赛2 1005 序列变换(lis变形)
- 2015百度之星初赛2 1005 序列变换(LIS变形)
- hdu5256 序列变换 百度之星初赛第二场 最长上升子序列变形
- 序列变换 二分搜索
- 百度之星1005 序列变换(lis)
- 2015Astar百度之星初赛 1005 序列变化
- C#特性
- 百度之星初赛(1)1001 超级赛亚ACMer
- 【MyEclipse使用教程】—如何设置jsp页面为默认utf-8编码
- 菜鸟学Android笔记(九):Schema之名称空间
- Android 监听ScrollView的滑动
- 百度之星初赛(1) 1003 序列变换 二分搜索
- Java多态性 父类引用指向子类对象
- 【学习拾遗】Jquery(二)--插件
- Android监听ScrollView滑动到顶端和底部
- leetcode ZigZag Conversion
- 栈(三):链式栈
- 走进算法
- 部分A+B
- 剑指offer--两个栈生成队列