Inverted Signs Gym-101522I
来源:互联网 发布:抑制性欲的药 知乎 编辑:程序博客网 时间:2024/06/05 11:59
Inverted Signs Gym-101522I
标签:思维&逻辑
题目链接
/* 题意:N个数,定义一个混乱度,sum|Hi+1 - Hi|(1 <= i <= N - 1),Hi可以为0, 可以翻转一个连续的符号相同的字串,来减小这个值,即负数字串->正数字串,反之成立, 求可以达到的最小的混乱度。 分析:选择一个区间只会对两个端点产生影响。模拟程序走一遍样例会很清晰。*/#include <stdio.h>#include <math.h>#include <queue>using namespace std;const int maxn = 1000005;int h[maxn];int main(){ int N, i; while(scanf("%d", &N) != EOF){ __int64 ans = 0; priority_queue <__int64> q; for(i = 1; i <= N; i++){ scanf("%d", &h[i]); if(i > 1) ans += fabs(h[i] - h[i - 1]); __int64 d = fabs(h[i] - h[i - 1]) - fabs(h[i] + h[i - 1]); q.push(d); } for(i = 0; i < 2 && !q.empty(); i++){ int u = q.top(); q.pop(); if(u > 0) ans -= u; } printf("%lld\n", ans); } return 0;}
阅读全文
0 0
- Inverted Signs Gym-101522I
- Wooden Signs Gym
- GYM 101128 E.Wooden Signs(dp)
- GYM 101128 E.Wooden Signs【Dp】
- CodeForces Gym 100735I
- Mirrored String I Gym
- Gym 101147.I
- Gym 101164.I
- Gym 101243.I
- Gym 101482. I
- Gym 101623I
- Gym 100499I (数学 模拟)
- Gym 100703I 尺取法
- Gym 100623I Important Wires
- codeforces Gym 101097 I Sticks
- Codeforces Gym 101164I Cubes
- Gym 101484 I Matrix Sum
- I - In Touch-Gym 100492I-水题
- Tensorflow -- 基础概念
- 小程序与共享图书的融合
- edmonds-karp算法求最大流
- Sliding Window Maximum:将每次滑动窗口内的最值保存
- 项目测试
- Inverted Signs Gym-101522I
- 使用IjkMediaPlayer结合surface
- 浅谈oracle优化中物化视图的查询重写
- 关于codeforces比赛规则介绍
- 图的遍历与最小生成树
- 博弈问题总集第三类----Staircase Nim
- [JZOJ5495]【清华集训2017模拟12.09】MiniumCut
- CSDN-markdown编辑器教程
- 配置远程maven仓库