Hdu 5248
hdu5248-序列变换
题意:
给你一个序列A,要求改变序列A中的某些元素的顺序,形成一个新的数列B,并保证数列B严格单调递增,求出最小代价。
代价计算公式 $ cost(a,b)=max(|A_i - B_i|) $ 。
解法:
和跳石头那道题类似,通过二分答案不断缩小范围,再每次贪心的取最小值即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
#define N 100010
int ans,cnt = 1;
int a[N],n,T,tmp;
inline bool check(int x) {
int pre = a[1] - x;
for(int i = 2 ; i <= n ; i++) {
if(a[i] + x <= pre) return 0;
pre = max(pre + 1, a[i] - x);
}
return 1;
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
tmp = 0;
for(int i = 1 ; i <= n ; i++) {
scanf("%d",&a[i]);
if(tmp < a[i]) tmp = a[i];
}
int l = 0, r = 0x3f3f3f, ans;
while(l <= r) {
int mid = (l + r) >> 1;
if(check(mid)) {
r = mid - 1;
ans = mid;
} else l = mid + 1;
}
printf("Case #%d:\n%d\n",cnt++,ans);
}
//system("pause");
return 0;
}
Hdu 5248的更多相关文章
- hdu 5248 序列变换(二分枚举)
Problem Description 给定序列A={A1,A2,...,An}, 要求改变序列A中的某些元素,形成一个严格单调的序列B(严格单调的定义为:Bi<Bi+,≤i<N). 我们 ...
- hdu 5248 贪心
题意:
- poj和hdu部分基础算法分类及难度排序
最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- 怎样理解Canvas
Canvas 是一种在网页中的画布, 是一个HTML5新增的标签, 是一种高效的绘制图形的技术, 在JavaScript中有一个专门的API用于给他赋能( CanvasRenderingContext ...
- 怎样修改 VS Code 主题?
方法1. 点击左上角 File > Preferences > Color Theme. 方法2. 使用快捷键: Ctrl + K , Ctrl + T PS: 查询各种操作的快捷键可以 ...
- Rikka with Competition hdu 6095
签到题目,排序然后按序清理掉一定会输的结果就可以. ac代码: #include <iostream> #include <cstdio> #include <cstri ...
- SpringBoot事务隔离等级和传播行为
一.开启事物管理 //import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBoo ...
- 微信公众号支付备忘及填坑之路-java
一.背景 最近公司给第三方开发了一个公众号,其中最重要的功能是支付,由于是第一次开发,遇到的坑特别的多,截止我写博客时,支付已经完成,在这里我把遇到的坑记录一下(不涉及退款).不得不吐槽一下,腾讯这么 ...
- vue组件常用传值
一.使用Props传递数据 在父组件中使用儿子组件 <template> <div> 父组件:{{mny}} <Son1 :mny="mny"&g ...
- OnePlus5刷 TWRP
# 安装adb apt install adb # 安装fastboot apt install fastboot # 进入bootloader模式 adb reboot bootloader # 刷 ...
- STM32工程模版
STM32工程模版,看过来 ST库源码去官方下载 创建工程目录 doc:存放说明文档 lib:存放库文件 listing:存放编译产生的中间文件 output:存放生成的文件 project:存放工程 ...
- SSISDB8:查看SSISDB记录Package执行的消息
在执行Package时,SSISDB都会创建唯一的OperationID 和 ExecutionID,标识对package执行的操作和执行实例(Execution Instance),并记录opera ...
- 1.SpringMVC 概述
SpringMVC 简介 SpringMVC 也叫 Spring web mvc ,属于表现层的框架.SpringMVC 是 Spring框架的一部分,是在Spring3.0后发布的 第一个Sprin ...