C - Functions again CodeForces - 789C (dp、思维)
C - Functions again
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long dp,maxx,dp2,maxx2,ans,a,b;
long long masx(long long a,long long b)
{
if(a>=b) return a;
else return b;
}
int main()
{
int n;
cin>>n>>a;
int h=1;
for(int i=0;i<n-1;++i)
{
scanf("%lld",&b);
int f = abs( a - b ) * h;
int f2 = abs( a - b ) * -h;
dp = masx( dp+f, f);
dp2 = masx( dp2+f2, f2);
maxx = masx( dp, maxx);
maxx2 = masx( dp2, maxx2);
h*=-1;
a=b;
}
ans = masx( maxx, maxx2 );
printf( "%lld", ans );
}
C - Functions again CodeForces - 789C (dp、思维)的更多相关文章
- Codeforces 407B Long Path(好题 DP+思维)
题目链接:http://codeforces.com/problemset/problem/407/B 题目大意:一共n+1个房间,一个人从1走到n+1,每次经过房间都会留下一个标记,每个房间有两扇门 ...
- Codeforces 1038D - Slime - [思维题][DP]
题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...
- codeforces 572 D. Minimization(dp+ 思维)
题目链接:http://codeforces.com/contest/572/problem/D 题意:给出一个序列,可以任意调整序列的顺序,使得给出的式子的值最小 题解:显然要先排一下序,然后取相邻 ...
- codeforces 1140D(区间dp/思维题)
D. Minimum Triangulation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces 985E Pencils and Boxes(dp+思维)
E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 1088E 树形dp+思维
比赛的时候看到题意没多想就放弃了.结果最后D也没做出来,还掉分了,所以还是题目做的太少,人太菜. 回到正题: 题意:一棵树,点带权值,然后求k个子连通块,使得k个连通块内所有的点权值相加作为分子除以k ...
- 【codeforces 789C】Functions again
[题目链接]:http://codeforces.com/contest/789/problem/C [题意] 看式子. [题解] 考虑最后的答案区间; 如果那个区间是从奇数位置的数字开始的; 那么奇 ...
- Codeforces Round #673 (Div. 2) C. k-Amazing Numbers (DP,思维)
题意:有一组数,分别用长度从\([1,n]\)的区间去取子数组,要求取到的所有子数组中必须有共同的数,如果满足条件数组共同的数中最小的数,否则输出\(-1\). 题解:我们先从后面确定每两个相同数之间 ...
随机推荐
- ESXI 7.0封装网卡驱动
前段时间配置的All In One 主机,由于华擎H410M-ITX/AC主板的板载网卡为intel I219-V,在安装ESXI后网卡无法驱动.查询之后发现原来ESXI7.0.2的版本不含该网卡驱动 ...
- Nacos详解
Nacos是什么 欢迎来到Nocos的世界! 组成部分 全称 描述 Na naming/nameServer 即服务注册中心,与 Spring Cloud Eureka 的功能类似. co confi ...
- Java读取文件后文件被占用
Java读取文件响应后文件一直被占用问题 原因: 由于是封装的函数,请求和响应对象都是 形参地址 虽然在此函数里关闭了输出流,但是由于有返回值,调用未结束,输出流无法提前关闭 解决: 1:调用函数后, ...
- MySQL 不四舍五入取整、取小数、四舍五入取整、取小数、向下、向上取整
总结了MySQL中取整和取小数中遇到的问题和解决的几个方法:不四舍五入取整.取小数.四舍五入取整.取小数.向下.向上取整. 其中: 不四舍五入取整(截取整数部分)就是'向下取整': 除了用trunca ...
- [Codeforces Round #816 (Div. 2)] D. 2+ doors
这次Div.2比之前我打的有些要难啊,前三道题就耗了好多时间,D题干脆摆烂了... 还是太逊了 对于一个\(x\),有\(x|y_i=z_i\),那么我们设\(num[x]=z_1\)&\(z ...
- 网络爬虫及openyxl模块
网络爬虫及openyxl模块 一.第三方模块简介 1.第三方模块的用处 python之所以在这么多的编程语言中脱颖而出的优点是有众多的第三方库函数,可以更高效率的实现开发 2.第三方模块的使用 1.第 ...
- Unity_UIWidgets - 组件AppBar
Unity_UIWidgets - 组件AppBar AppBar 构造 构造png观看 使用代码 使用效果 AppBar使用结束 结语 图标Icon QQ 今日无推荐 Unity_UIWidgets ...
- 【分析笔记】全志平台 gpio-keys 驱动应用和 stack crash 解决
内核配置 内核版本:Linux version 4.9.56 make ARCH=arm64 menuconfig Device Drivers ---> Input device suppor ...
- 阿里百秀后台管理项目笔记 ---- Day04
来吧展示: step 1 : 实现评论管理数据渲染 利用 ajax 创建接口得到数据使用模板引擎渲染页面 1.1 引入文件 <script src="/static/assets/ve ...
- redis-04配置文件
1.daemonize no # By default Redis does not run as a daemon. Use 'yes' if youneed it.# Note that Redi ...