和NOIP2018DAY1T1类似的题目,但思维难度高多了。

这题既可以抬高路面,也可以降低路面,而且目标平面不确定,就难起来了。

但是两道题的基本思路几乎一样,同样我们将 2~n 的高度差分,1之所以不要差分是因为最终的高度是不确定的。

所以现在的目标就是将这个差分数组的任意一个位置 +1/-1 ,另一个位置 -1/+1,使 2~n 的差分数组变成 0,显然最少次数就是 max(正数之和,负数绝对值之和)

第二问要求最终的可能平面有多少种,考虑操作的过程中当正的或负的已经被搞成 0 ,只剩一部分负的或正的,那这对应原来的数组就是从 2~n 单调的,所以1的取值只能在最高点和最低点之间,这样才能保证次数最少,答案就是 abs(正数之和 - 负数绝对值之和) + 1

#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <assert.h>
#include <algorithm> using namespace std; #define LL long long
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define GO debug("GO\n") inline int rint() {
register int x = 0, f = 1; register char c;
while (!isdigit(c = getchar())) if (c == '-') f = -1;
while (x = (x << 1) + (x << 3) + (c ^ 48), isdigit(c = getchar()));
return x * f;
} template<typename T> inline void chkmin(T &a, T b) { a > b ? a = b : 0; }
template<typename T> inline void chkmax(T &a, T b) { a < b ? a = b : 0; } #define int LL
signed main() {
#ifndef ONLINE_JUDGE
freopen("xhc.in", "r", stdin);
freopen("xhc.out", "w", stdout);
#endif
int n;
cin >> n;
int x = 0, y = 0, last, now;
cin >> last;
for (int i = 2; i <= n; ++ i) {
cin >> now;
if (now > last) y += now - last;
else x += last - now;
last = now;
}
cout << max(x, y) << endl << abs(y - x) + 1 << endl;
return 0;
}

最新文章

  1. 求android ble 解决方案!
  2. 转:Log4j使用
  3. Microsoft.Bcl.Build 1.0.10 稳定版发布
  4. WCF开发指南之构建服务
  5. linux磁盘空间清理
  6. 使用scrapy爬取网站的商品数据
  7. IE兼容CSS3圆角border-radius的方法(同时兼容box-shadow,text-shadow)
  8. Javascript:getElementsByClassName
  9. Android_declare-styleable_自己定义控件的属性
  10. Blend4精选案例图解教程(二):找张图片玩特效
  11. [转]Data Structure Recovery using PIN and PyGraphviz
  12. centOS7 mini配置linux服务器(一)安装centOs7
  13. 老李分享:Android性能优化之内存泄漏2
  14. 201421123042 《Java程序设计》第5周学习总结
  15. ECMAscript5中的map
  16. PxCook 像素大厨 标注切图,一起搞定!专注设计本质
  17. c# 调试运行后,debug目录为空
  18. Unity Shader-法线贴图(Normal)及其原理
  19. 【DP】【CF1099C】 Postcard
  20. 用gcc编译成可执行程序 (转)

热门文章

  1. oracle 12如何解锁账户锁定状态及修改忘记的密码
  2. iOS:SQL
  3. 冒泡排序_c++
  4. NodeJ node.js Jquery Ajax 跨域请求
  5. Xdebug 备注
  6. Java分布式锁之数据库方式实现
  7. PHP二维码生成
  8. Python实现音乐的剪辑
  9. 大数据学习--day04(选择结构、循环结构、大数据java基础面试题)
  10. linux 通过 openconnect 来连接学校内网