hihocoder Challenge 29 D. 不上升序列
来源:互联网 发布:php开源在线教育系统 编辑:程序博客网 时间:2024/06/04 19:34
这场爆零比赛题目还是要补的
这道题据说是出烂掉的原题,我找了下
CF13.C/ CF371 div1 C,一模一样 我服这群原题大佬
i==1 Fi[x]=minxy=1|A[i]−y| Otherwise
Fi[x]=minxy=1(Fi−1[y]+|A[i]−y|)
显然
那么我令
Changei−1<=A[i] ,那么必在A[i] 达到理想状态,和OPTi−1 结合为OPTi 鞋履更陡,
Changei−1>A[i] ,那么x<=A[i] 斜率递减,x>A[i] 会在一个地方达到交点,必是Changei−1 ,那个就是最优点
好吧我还是不太理解,我尽力了,发一下链接,CF371 div1C comment
#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime>#include <algorithm>#include <iostream>#include <map>#include <set>#include <queue>#include <cmath>using namespace std;typedef long long ll;#define lson l,m, rt<<1#define rson m+1, r, rt<<1|1const int N = 2e5+5;const int INF = 0x3f3f3f3f;int main() { int n; while(~scanf("%d", &n) ) { priority_queue<int> Q; int ans = 0; for(int i = 0; i < n; ++i) { int a; scanf("%d", &a); a = -a; Q.push(a); if(Q.top() != a) { ans += Q.top() - a; Q.pop(); Q.push(a); } } printf("%d\n", ans); } return 0;}
阅读全文
0 0
- hihocoder Challenge 29 D. 不上升序列
- [堆] hihoCoder Challenge 29 D. 不上升序列
- hihoCoder挑战赛29 D.不上升序列
- hiho-hihoCoder挑战赛29-D-不上升序列
- hihocoder Challenge 29 A.序列的值
- hihocoder#1529 : 不上升序列&&Codeforces-713C:Sonya and Problem Wihtout a Legend(思维)
- hihocoder Challenge 29 B.快速乘法
- 最长不上升子序列
- 最长不上升子序列
- pku1887 最长不上升子序列
- poj 1887 最长不上升子序列
- 【转载】【线段树】最长不上升序列
- codevs-3955 最长不上升子序列
- 最长不连续上升序列----动态规划
- shuoj1936-D序列—最长上升子序列
- ZOJ2283 Challenge of Wisdom(DP+二分求最长非上升子序列)
- rqnoj-217-拦截导弹-最长不上升子序列以及不上升子序列的个数
- LuoguP2757 导弹的召唤 解题报告【最长上升子序列+最长不上升子序列】
- 朵唯S2l 驱动安装 刷机 Imei号找回方案(应该也适合同类国产机)
- 毕业那年
- FOF常用的七种投资策略全解析
- Python实现结构体
- MAPREDUCE使用(整理)
- hihocoder Challenge 29 D. 不上升序列
- Android selector配合setSelected使用时的坑
- VS C语言xml文件读取
- timedatectl
- 端口号相关
- 浮点数值转十六进制字符串
- HTML5新控件
- 类变量与实例变量的初始化过程
- [vue.js] prop验证没有错误信息的可能原因:没有使用开发者版本