codeforces 360 B
题目大意:给你你个长度为n的数列a,你最多改变k个值,max{ abs ( a[ i + 1] - a[ i ] ) } 的最小值为多少。
思路:这个题很难想到如何取check。。 二分最小值,然后用dp进行check,dp[ i ]表示前 i 项中第 i 个不改变最少
需要改变几个值。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int n, k, dp[N];
int a[N]; bool check(LL mx) {
for(int i = ; i <= n; i++) dp[i] = i - ;
for(int i = ; i <= n; i++) {
for(int j = ; j < i; j++) {
if(abs(a[i] - a[j]) <= mx * (i - j)) {
dp[i] = min(dp[i], dp[j] + i - j - );
}
}
}
for(int i = ; i <= n; i++)
if(dp[i] + n - i <= k) return true;
return false;
} int main() {
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]);
LL l = , r = 2e9, mid, ans = 2e9;
while(l <= r) {
mid = l + r >> ;
if(check(mid)) r = mid - , ans = mid;
else l = mid + ;
}
printf("%d\n", ans);
return ;
} /*
*/
codeforces 360 B的更多相关文章
- [codeforces 360]A. Levko and Array Recovery
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...
- codeforces 360 E - The Values You Can Make
E - The Values You Can Make Description Pari wants to buy an expensive chocolate from Arya. She has ...
- codeforces 360 D - Remainders Game
D - Remainders Game Description Today Pari and Arya are playing a game called Remainders. Pari choos ...
- codeforces 360 C
C - NP-Hard Problem Description Recently, Pari and Arya did some research about NP-Hard problems and ...
- 套题 codeforces 360
A题:Opponents 直接模拟 #include <bits/stdc++.h> using namespace std; ]; int main() { int n,k; while ...
- codeforces 360 C - NP-Hard Problem
原题: Description Recently, Pari and Arya did some research about NP-Hard problems and they found the ...
- Codeforces Round #360 div2
Problem_A(CodeForces 688A): 题意: 有d天, n个人.如果这n个人同时出现, 那么你就赢不了他们所有的人, 除此之外, 你可以赢他们所有到场的人. 到场人数为0也算赢. 现 ...
- Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 暴力并查集
D. Dividing Kingdom II 题目连接: http://www.codeforces.com/contest/687/problem/D Description Long time a ...
- Codeforces Round #360 (Div. 2) D. Remainders Game 数学
D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and ...
随机推荐
- github上面创建文件夹
- web.xml中出现<servlet-name>default</servlet-name>是什么意思?
转载自:http://blog.csdn.net/hello5orld/article/details/9407905 在web.xml文件中经常看到这样的配置<servlet-name> ...
- centOS 安装Python3与python2并存
如果本机安装了`python2`,尽量不要管他,使用`python3`运行python脚本就好,因为可能有程序依赖目前的`python2`环境, 比如`yum`!!!!! 不要动现有的`python2 ...
- jquery的基础语法、选取元素、操作元素、加事件、挂事件及移除事件
jquery基础知识 1.jquery文件的引入,所有的js代码要写在下面那段代码下面. <script src="../jquery-1.11.2.min.js">& ...
- PHP做分页查询(查询结果也显示为分页)
1.先把数据库里所有的数据分页显示在页面,并在显示数据的表格上方加上查询表单. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ...
- position的用法与心得
position的四个属性值: relative absolute fixed static 为了便于理解,首先创建对应的div <div class="main"> ...
- 模型验证与模型集成(Ensemble)
作者:吴晓军 原文:https://zhuanlan.zhihu.com/p/27424282 模型验证(Validation) 在Test Data的标签未知的情况下,我们需要自己构造测试数据来验证 ...
- linux进程管理-定时定期执行任务
0.计划任务的命令: at 安排作业在某一时刻执行 batch 安排作业在系统负载不重时执行 crontab 安排周期性运行的作业 1.at命令用法: 安排命令或者多个命令在指定的时间运行一次 语法 ...
- SQL注入之逗号拦截绕过
目前所知博主仅知的两个方法 1.通过case when then 2.join [一]case when then mysql,,,,,,, ) ) end; +----+-----------+-- ...
- 9.quartus_warning_altera_reserved_tck
编译的时候没有注意,整个工程都可以在板子上跑起来.但是做Powerplay的时候,出现了这个Critical Warning:. Critical Warning: The following clo ...