Levko and Array】的更多相关文章

[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of…
链接:CF360B 题目: B. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all. Levk…
Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all. Levko thinks that the…
刚才面试了一个蛮有意思的DP题目,脑子断片,没写出来,不过早上状态还是蛮好的 一个长度为n的序列最多改变k次,使相邻两数之差绝对值的最大值最小 三维的dp我先尝试写一下 Codeforces 360B Levko and Array 其实是n^2logm的,太nb了 去二分答案这个很好想,因为既然这个数满足,大于它肯定满足,然后就是去判断这个数字存不存在了.很容易想到贪心,但是贪心会有个问题,就是你无法确定你要修改的哪个数,很容易你就可以找到自己的bug.最后这个是个dp,dp[i]表示从n到i…
Discription Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all. Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculated by the formula: The less value c(a)…
题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数据难道又水了... #include <stdio.h> #include <string.h> #include <iostream> #include <queue> #include <algorithm> using namespace st…
http://codeforces.com/contest/361/problem/D 用二分搜索相邻两个数的差的绝对值,然后用dp记录数改变的次数.dp[i]表示在i之前改变的次数,如果|a[i]-a[j]|<=(i-j)*mid 需要改变. #include <cstdio> #include <cstring> #include <algorithm> #define LL __int64 using namespace std; ; ]; int n,k;…
http://codeforces.com/contest/361/problem/C 这道题倒着一次,然后正着一次,在正着的一次的时候判断合不合法就可以. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; ],ans[]; ],l[],r[],d[]; int n,m; int flag; int main() { while(scanf("%d%…
题意: 有一长度为n的正整数序列,你可以选择K个数字任意改变它,使得$max \{ a(i+1) - a(i) \} $ 最小,求最小值. 解法: 1.$O(n^2log(MAX_A) )$,考虑二分出$d = max \{ a(i+1) - a(i) \} $,这样考虑dp $f(i,j)$表示前i个数字,末位的数字为j的时候最少修改了多少数字 $f(i,j) = min \{ f(i-1,k) \} (j-d ≤ k ≤ j+d,j = a(i))$ $f(i,j) = min \{ f(i…
题目链接:http://codeforces.com/contest/361/problem/D 题意:最多可以修改K次数字,每次修改一个数字变成任意值,C=max(a[i+1]-a[i]):求操作之后最小的C. 题解:由于n和k比较小其实可以考虑一下区间dp,但是如果区间dp要求的话估计是要3维的显然会炸掉. 于是可以考虑一下二分一下结果c的值,为什么要考虑二分呢?主要是由于c的值与修改的次数是成正比的 显然改的越多c值肯定越少,所以可以二分.然后就是如何判断是否满足条件了,这里要用到dp,设…